Hello,
I made a switch statement to control the up and down movement for a pin. The script is attached to a simple cube and everything works fine because he prints everything in the log. What I want to do is:
Click the cube once and the pin starts moving, click the cube again and it stops moving.
I think I am pretty close because I can either start it or stop it depending on what I change the ’ state’ value to. When I keep it on 1 it starts moving onclick but doesn’t stop and vice versa.
Here is my code:
void Update ()
{
if (Input.GetMouseButtonDown (0)) {
pinToggle ();
}
}
void pinToggle ()
{
int state = 1;
switch (state) {
case 1:
pinmovement.pinStart = true;
Debug.Log ("PinStart state: " + pinmovement.pinStart);
break;
case 2:
pinmovement.pinStart = false;
Debug.Log ("PinStart2 state: " + pinmovement.pinStart);
break;
}
}
The pinmovement is another script that containts the pin code and pinStart is a boolean to control wether it has to move or not.