Here’s the code I don’t see what is wrong,
public class CameraSwitch : MonoBehaviour
public GameObject camera1;
public GameObject camera2;
void Start ()
void Update ()
if((Input.GetButtonUp("Camera") = true) & (camera1.SetActive(true)))
camera1.SetActive = false;
camera2.SetActive = true;
else if((Input.GetButtonUp("Camera") = true) & (camera1.SetActive(false)))
camera1.SetActive = true;
camera2.SetActive = false;
I’m sure it should work, but it doesn’t
Thank you for any help.
You’ve forgotten the second = form the equality check in your ifs. Same applies to your and operation.
The euqality operator is == , this checks if the left side and the right side are equal. For value types this means if their values are euqals, for reference types it means if their references are equals. This operator always returns true or false. Example:
x == 2; is read as: “does x equal 2?”
The assignment operator = means to set the right hand side to the left hand side. i.e.
x = 2; means “set x to 2;”.
The & is a bitwise AND operation, while && is the normal AND.
So in your code you are telling the code basically, "if (set the button for Camera is released to true and add set camera1 to false). Which doesn’t make any sense.
Your code should instead read : “if (the button for Camera is released and camera1 is active)”
if((Input.GetButtonUp("Camera") == true) && (camera1.enabled == true))
I’ll let you apply similar changes to the rest of your ifs.