i need to run the lerp in a function and NOT in update, i have included 2 scripts one that runs in update to show what i need to replicate in a non update function, the other script shows the problem when lerp is run in a function, just create 2 cubes and put one script on each, run and press the space bar to see the problem, i have tried to use a co-routine ienumerator but still cannot get it to run like it does in the update script, i have been tearing my heair out trying to sort this but it just wont work for me.
as you will see i need to rotate the cube by 90 degrees on a random axis, but for my game i need it to run in a function and not in update
any help greatly thanked
csharp:
using UnityEngine;
public class ROTATE9 : MonoBehaviour
{
public float smooth = 1f;
private Vector3 turn;
private Quaternion targetRotation;
void Start(){
targetRotation = transform.rotation;
}
void Update () {
if(Random.value<0.5f)
turn=Vector3.up;
else
turn=Vector3.left;
if (Input.GetKeyDown (KeyCode.Space)) {
targetRotation *= Quaternion.AngleAxis(90, turn); // USE 90 or -90 AND UP / FORWARD / OR LEFT
}
transform.rotation= Quaternion.Lerp (transform.rotation, targetRotation , 10 * smooth * Time.deltaTime);
print(transform.localEulerAngles.y);
}
}
using UnityEngine;
public class ROTATE11 : MonoBehaviour
{
public float smooth = 1f;
private Vector3 turn;
private Quaternion targetRotation;
void Start(){
targetRotation = transform.rotation;
}
void Update(){
if (Input.GetKeyDown (KeyCode.Space)) {
Rotate ();
}
}
void Rotate () {
if(Random.value<0.5f)
turn=Vector3.up;
else
turn=Vector3.left;
targetRotation *= Quaternion.AngleAxis(90, turn); // USE 90 or -90 AND UP / FORWARD / OR LEFT
transform.rotation= Quaternion.Lerp (transform.rotation, targetRotation , 10 * smooth * Time.deltaTime);
print(transform.localEulerAngles.y);
}
}
sorry for posting the scripts as text as i could not work out how to post the scripts properly
thank you