0

I have two buttons. one activates a method that creates a cube, and one create a purple block (see all in video). when I click one button it activates the other button. can anybody help?

The Video

Here is some code:

Button 1 activates this method:

public void AddObsticale(int unit)
{
    Vector3 unitPos = u.Units[unit].transform.position;
    arrow.transform.position =new Vector3(unitPos.x + 4.5f, unitPos.y + 1, unitPos.z - 5f);
    arrow.SetActive(true);
    StartCoroutine(ArrowChoose());
}

IEnumerator ArrowChoose()
{
    yield return new WaitUntil(() => Input.GetKeyDown(KeyCode.Return));
    GameObject g = Instantiate(obsticlePrefab, new Vector3(0, 0.5f, arrow.transform.position.z), Quaternion.identity, gameObject.transform);
    arrow.SetActive(false);
}

Button 2 (which should not be activated) activates this method:

public void AddUnit()
{
    count++;
    GameObject g = Instantiate(unitPrefab, new Vector3(0, 0, (count - 1) * unitSize.z), Quaternion.identity, unitsParent.transform);
    units.Add(g);
    unitText.text = "Units: " + count;
}
3
  • Maybe something wrong with the calling objects/events or the delegate pipeline? It will help if you are able to share some code. Commented Mar 10, 2020 at 9:10
  • You shouldn't post it as a video. For example I am at work atm, and I can't watch a video, therefore I can't help you. Also, some people won't bother with your question, cause they don't want to spend time for that. So always post your code Commented Mar 10, 2020 at 9:26
  • I put some code up Commented Mar 10, 2020 at 9:42

1 Answer 1

2

I fixed the problem:

The problem was in this line:

yield return new WaitUntil(() => Input.GetKeyDown(KeyCode.Return));

the return key activates the button automatically, because of unity, as soon as I changed the key to a different one, say KeyCode.V the problem was gone!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.