Variable value does not change
private Rigidbody rb;
private float rotateHorizontal;
void Update ()
{
Vector3 movement = new Vector3( 0.0f , 0.0f , rotateHorizontal);
rb.AddTorque(movement * speed);
Debug.Log(rotateHorizontal);
}
public void MoveLeft()
{
rotateHorizontal = 1f;
}
Hi, I use the MoveLeft() function with UI Button Event Trigger. But when I press the button the value of rotateHorizontal does not change. This script is on a prefab.
Comment
The value should change once since you make a simple assignment.
Are you sure $$anonymous$$oveLeft
is called? Try to use a Debug.Log
to find out.
If the function is not called, make sure it is "attached" to the correct event in the inspector.
Finally, check the answer given here: https://answers.unity.com/questions/1402544/so-my-buttons-stop-working.html
Good day.
For your explanation I understand you have a button with the method $$anonymous$$oveLeft() asigned on mouse click. CAn you post a comment with a screenshot iof that button inspector?
Thanks!