I am a super novice who very slowly is making a project. Sorry for my ignorance ahead of time. What I want to do is rotate a 2D object in 3D space for a specific amount of time on a key press. I can rotate on a keypress but I dont know how to add a time element. An example would be that I want the 2D object to rotate for 3 seconds on a keypress. Below is the basic rotate script I have so far.
public class Rotator : MonoBehaviour {
void FixedUpdate ()
{
if (Input.anyKey)
transform.Rotate (new Vector3 (0, -90, 0) * Time.fixedDeltaTime);
}
}
I dont even know if I am thinking about this the right way. Should I be trying to set up a rotate target like 180 degrees that is completed over a period of time? Thanks.
using UnityEngine;
using System.Collections;
public class rot : MonoBehaviour {
public GameObject OurObject; // the object you want to rotate.
public float RotationTime = 3f; // In seconds
public float RotationSpeed = 0.5f; // round per second
float timeLeft;
void Update() {
timeLeft -= Time.deltaTime;
if (Input.GetKey("r") && timeLeft < 0){
timeLeft = RotationTime;
}
if (timeLeft > 0){
OurObject.transform.Rotate(0,0, Time.deltaTime * RotationSpeed * 360 );
}
}
}