I have very recently started to learn Unity.
I'm trying to write code that will make a character swing a flag. I want to use this object and rotate the arm up and down. So I need to make it rotate up and down with within 30 degrees.
This is my attempt but it simply keeps on turning. How would I make the hand rotate in motion within the interval [-30, 30] degrees.
private GameObject myobject;
public float timeElapsed =0;
public float delay = 3.0f;
float OO = 0.0f;
void Start () {
myobject = GameObject.Find ("rightarm").gameObject;
}
void Update () {
timeElapsed += Time.deltaTime;
Debug.Log (timeElapsed);
if (timeElapsed >= delay) {
OO = 30.0f;
timeElapsed = 0;
if (myobject.renderer.enabled == false) {
myobject.renderer.enabled = true;
}
myobject.transform.Rotate (OO, 0.0f, 0.0f);
}
else
{
myobject.transform.Rotate (-OO,0.0f, 0.0f );
}
}