- Home /
UI Button Event Trigger Update Selected not working
I have a script that adds a force to an object. When the UI Button is held down, I want this force to be added every frame. Using the Pointer Down event trigger doesn't work as it only adds the force for the first frame, but the Update Selected trigger doesn't apply a force at all. Am I misunderstanding how Update Selected is meant to be used, and what am I doing wrong?
The function I am calling in Update Selected:
public void force() {
car = GameObject.Find ("Car");
float thrustval = 5;
float angle = lander.transform.eulerAngles.z;
float ycomp = thrustval * Mathf.Cos (angle * Mathf.Deg2Rad);
float xcomp = -1 * (thrustval * Mathf.Sin (angle * Mathf.Deg2Rad));
Vector2 components = new Vector2 (xcomp,ycomp);
car.rigidbody2D.AddForce (components,ForceMode2D.Force);
}
Comment