Himanshu Himanshu - 15 days ago 5
C# Question

How to stop rotation of 3D plane after some interval of time of rotation in unity?

I am using this script to rotate my 3D plane, but the issue is that it's infinite. I'm new to unity, can anybody help me out to stop the rotating of the plane after some interval of time or after some rotation.

using UnityEngine;
using System.Collections;

public class rotationAnimation : MonoBehaviour {

// Use this for initialization
void Start () {
}

// Update is called once per frame
void Update () {
float translation = Time.deltaTime * 30;

// ...also rotate around the World's Y axis
transform.Rotate (Vector3.up, translation, Space.World);
}
}

Answer

here's a simple example

public float duration = 10f;//run code for this seconds
private float _currentTime;
void Start () {
   _currentTime = 0f;
}

public void Update(){
   if(_currentTime < duration){

       float translation = Time.deltaTime * 30;

       // ...also rotate around the World's Y axis
       transform.Rotate (Vector3.up, translation, Space.World);
       _currentTime += Time.deltaTime;
   }
}
Comments