Hello, I am calling a function through the new Unity UI system but it is not looping my function. I have attached my game object to the event trigger and the function I am calling is “TurnLeft”.
I am using the On Pointer Down event so it should play continuously.
Here is the function as well. I am trying to make my character rotate using the new UI system. Please help, I can’t seem to find the solution.
function TurnLeft(){
transform.Rotate(Vector3(0,-1,0)*turnSpeed* Time.deltaTime);
}
OnPointerDown is essentially the same as GetKeyDown, in that it only triggers when the key is initially pressed.
To loop this, I’d suggest having the OnPointerDown switch on a boolean. Something along these lines:
var turn : boolean;
function Update(){
if(turn){
TurnLeft();
}
}
function Turn(which : boolean){
turn = which;
}
function TurnLeft(){
transform.Rotate(Vector3(0,-1,0)*turnSpeed* Time.deltaTime);
}
And then have your OnPointerDown call the Turn() function, specifying if you want it on or not.