I am making a simple game where you are a bomber plane and i want to rotate the the plane slightly when flying left or right. It will rotate, but not go back. I will also need to replace yield return new WaitFor seconds with something with on key release
public GameObject plane;
public GameObject WingTarget;
public GameObject westWingStart;
public GameObject westWingEnd;
public GameObject eastWingStart;
public GameObject eastWingEnd;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.A))
{
StartCoroutine (WingTurn());
}
if (Input.GetKeyDown(KeyCode.D))
{
StartCoroutine (WingTurnE());
}
plane.transform.rotation = Quaternion.Lerp(plane.transform.rotation, WingTarget.transform.transform.rotation, 0.25f);
}
IEnumerator WingTurn()
{
WingTarget.transform.rotation = westWingEnd.transform.rotation;
yield return new WaitForSeconds (0.05f);
WingTarget.transform.rotation = westWingStart.transform.rotation;
}
IEnumerator WingTurnE()
{
WingTarget.transform.rotation = eastWingEnd.transform.rotation;
yield return new WaitForSeconds (0.05f);
WingTarget.transform.rotation = eastWingStart.transform.rotation;
}
}
WingTarget, westWingStart, westWingEnd, eastWingStart, eastWingEnd; are all children of the plane. the starts have a rotation of 0 and the ends have a rotation of x -30 and 30 respectively.