I'm designing a script that checks if a certain key is pressed, as well as if a certain GameObject is in the correct z position { public KeyCode qpress; public Transform qobj; public Transform perf1; void Update () { if (Input.GetKeyDown(qpress)) & (qobj.position.z <= perf1.position.z); } } However, visual studio gives me an error message on line 7, saying "Cannot take the address of the given expression". What am I doing wrong?
You are using a single ampersand (&)... for logical "AND" operator you want to use double ampersand (&&).
I don't get the error anymore, but it does not output anything in game. Why is this void Update () { if (Input.GetKeyDown(qpress) && qobj.position.z <= perf1.position.z && qobj.position.z >= perf2.position.z) { Debug.Log("PERFECT"); } } I don't get the error anymore, but it still does not output anything in game, even though the GameObject has a z coordinate between the two transforms. Why is this?
Just put a breakpoint on the `if` and check the values. Maybe you have perf1 and perf2 swapped? Also, use Code (csharp): tags to avoid the clipping you have in your last post.
I see two && sets, so you have three conditions, do you meet all three? Did you debug qobj.position.z right before the if statement to see what that value is? And use code tags when posting code https://forum.unity.com/threads/using-code-tags-properly.143875/ Which @dgoyette beat me to. lol