Hi everyone. I’m new at coding and I’m trying to figure out how to stop the rotation of my sprite at a certain rotational speed. Here’s my code:
using UnityEngine;
using System.Collections;
public class PlayerScript : MonoBehaviour {
private float initializationTime;
public float InitialRotation = 100;
private float FinalRotation;
// Use this for initialization
void Start () {
initializationTime = Time.timeSinceLevelLoad;
}
// Update is called once per frame
void Update () {
float timeSinceInitialization = Time.timeSinceLevelLoad - initializationTime;
FinalRotation = InitialRotation * Time.deltaTime * timeSinceInitialization;
if (FinalRotation <= 102)
{
transform.Rotate (0, 0, FinalRotation);
}
else
{
transform.Rotate (0, 0, 102);
}
}
}