- Home /
Using different reture types then void
So I'm not sure it this is exactly where I should be posting this or not but I need some help with my code.
public bool HandleMovement(bool isWorking)
{
if (Input.GetKeyDown("a"))
{
transform.Translate(-1f, 0f, 0f);
}
if (Input.GetKeyDown("d"))
{
transform.Translate(1f, 0f, 0f);
}
return true;
}
I have this code with the return type of bool because I want to turn it off/false when it collide with another gameobject. This is my attempt:
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Floor")
{
StopCoroutine(coroutine);
HandleMovement(false);
}
}
I'm not the best at coding yet so I'm not too sure how I get it to change to false. Thank you for any and all help!
Answer by adrienPlayerium · Aug 08, 2017 at 11:46 PM
Hi @technano , I want to help you out ~ I think you got confused. Right now your HandleMovement function will always return true, and it doesn't use its argument bool isWorking.
I am not sure if I understood what you were after but this might work for you:
public bool HandleMovement(bool isWorking)
{
if(!isWorking) return false;
if (Input.GetKeyDown("a"))
{
transform.Translate(-1f, 0f, 0f);
}
if (Input.GetKeyDown("d"))
{
transform.Translate(1f, 0f, 0f);
}
return true;
}
I see what I missed now! Thank you! But is still isn't returning false when I call the method in the OnCollisionEnter method
Your answer
Follow this Question
Related Questions
Access a variable from another script in update function 1 Answer
Door Script 1 Answer
How do I check if all booleans in an array are true? 2 Answers
Trigger won't read my Bool change 1 Answer