Hello i m trying to rotate my object smoothly over MouseButtonDown and rotate to identity position on MouseButtonUp and this code rotate my GameObject smoothly but it won't come back to identity position in time.
void Update ()
{
if (GameControls.Games.stateOfGame == GameControls.gameState.inStart || GameControls.Games.stateOfGame == GameControls.gameState.inPlay) {
if (Input.GetMouseButtonDown (0) || Input.GetKeyDown (KeyCode.Space)) {
StartCoroutine(FlyCat ());
}
if (Input.GetMouseButtonUp (0) || Input.GetKeyUp (KeyCode.Space)) {
StartCoroutine (ResetCat ());
}
}
}
IEnumerator FlyCat()
{
animate.enabled = false;
rigidbodyObject.bodyType = RigidbodyType2D.Dynamic;
tempTimer = 0.0f;
if (rigidbodyObject.position.y < maxUpperBorder) {
rigidbodyObject.velocity = Vector2.zero;
rigidbodyObject.AddForce (jumpForce);
while (tempTimer < 0.5f) {
tempTimer += Time.deltaTime;
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.Euler (rotationForce), Time.deltaTime * smooth);
}
rigidbodyObject.gravityScale = gravity;
yield return null;
}
if (InstantiateOnce == true) {
InstantiateOnce = false;
GameControls.Games.GamePlay ();
}
yield return null;
}
IEnumerator ResetCat()
{
while (tempTimer > 0f) {
Debug.Log (tempTimer);
tempTimer -= Time.deltaTime;
transform.rotation = Quaternion.Inverse (Quaternion.Euler(rotationForce));
}
transform.rotation = Quaternion.identity;
yield return null;
}