- Home /
Script to Exit in play mode-This is my script attached to a cube for movement,i want to make this script exit after 10 seconds in the play mode...any1 pls help??
using UnityEngine; using System.Collections;
public class PlayerScript : MonoBehaviour {
public float moveSpeed=10;
public void Update() { float moveforward=moveSpeed Time.smoothDeltaTime Input.GetAxis("Vertical"); float moveLeft=moveSpeed Time.smoothDeltaTime Input.GetAxis("Horizontal");
transform.Translate(Vector3.forward moveforward); transform.Translate(Vector3.left moveLeft);
}
}
Do you mean you want to stop the script running(or the update function running) after 10 seconds.
Answer by Myhijim · Jul 05, 2012 at 12:03 PM
You could try using a for loop to fix this
for(i=0;i<=(10*Time.smoothDeltaTime);i++)
{
//Do your code
}
Hope this helps(and works)
~ Myhijim
Answer by tuhinbhatt · Feb 17, 2013 at 06:00 PM
Change your update to this and you should get your desired functionality. The below code when the game played will run for only 10 seconds.
void update()
{
if(Time.timeSinceLevelLoad<10f)
{
float moveforward=moveSpeed * Time.smoothDeltaTime * Input.GetAxis("Vertical");
float moveLeft=moveSpeed * Time.smoothDeltaTime * Input.GetAxis("Horizontal");
transform.Translate(Vector3.forward * moveforward); transform.Translate(Vector3.left * moveLeft);
}
}
If i am wrong in understanding what exactly you are trying to acheive then please leave quesition in the comment and i will try to help you out.
Your answer