is it possible to make a if statement in a f statement? something like this: Code (csharp): function Update () { if(Input.GetKeyDown("space")){ if(gameObject.GetComponent("emptyScript").enabled = true){ print("emptyScript is enabled"); } else(gameObject.GetComponent("emptyScript").enabled = false){ print("emptyScript is disabled"); } } }
Sure it is possible and I use it really often. I don't understand your question, because you posted the code above. It's your code? Why do you don't test yourself? When I'm trying out something and it don't work for days I post my question here normally. You could always test out such things with Debug.Log(); and get a message what's going on.
I thoght that it isn't possible cause i get 3 errors that doesen't make sense :c 1. On (3.67) BCE0044: expecting ), found "=". 2. On (3.69) BCE0043: unexpected token: true. 3. On (4.56) BCE0043: expecting :, found ";".
I thoght that it isn't possible cause i get 3 errors that doesen't make sense :c 1. On (3.67) BCE0044: expecting ), found "=". 2. On (3.69) BCE0043: unexpected token: true. 3. On (4.56) BCE0043: expecting :, found ";".
Another error is that you added a condition after "else". This is not allowed. The quick solution is to write "else if" instead of "else", but I seriously suggest to learn the basics of programming first before diving into game development...
To summarize Ricks and Elryk's posts: Code (csharp): function Update () { if(Input.GetKeyDown("space")){ if(gameObject.GetComponent("emptyScript").enabled == true){ print("emptyScript is enabled"); } else{ print("emptyScript is disabled"); } } }