- Home /
Bool changing automatically...
Hi !
Any ideas why my bool goes to true as soon as I press E in my game ?
Just trying to make it so that if the bool is set to true, and the player is in the collider AND he presses E, the collider moves.
But if the bool is on false and I press E, the bool changes to true and the collider moves.
public float speed = 8f;
public bool Up = false;
void OnTriggerStay (Collider other)
{
if ((other.gameObject.tag == "Player") && (Input.GetKey(KeyCode.E)) && (Up = true))
transform.Translate(Vector3.up * speed * Time.deltaTime);
}
Thanks for the help !
Also looking into making a list instead of bools, some basically have a list of Up, Down, Left, Rift. So if Right is selected in the drop down, do this. If Right is selected in the drop down, do that... etc...
Any pointers ? Should I use enums ?
Hyper
Also just as a tip, you should start variables with lower case character for first word, not required just convention xd
Answer by ryandotdee · Feb 06, 2015 at 03:49 PM
Because you are missing an = sign in your conditional
&& (Up = true))
should be
&& (Up == true))
Bahaha ! You absolute legend ! :D Well that's what I get for coding all day, can't see anything anymore. Thanks a lot :)
Answer by AngryBurritoCoder · Feb 06, 2015 at 03:31 PM
Check , maybe it's ticked to true in inspector of the script component in unity editor. Or your changing it in another script
As I said "if the bool is on false and I press E, the bool changes to true and the collider moves."
Which means when I Press E, the bool goes from false to true...
I've tried an empty scene with just that script and my character controller.
Your answer
