Well, this is the code that I’ve placed inside a 3D asset. This code uses a timer to update other assets.
I’,m sorry I’ve placed all the code in the script, but all the functions are responsable, more or less, for the timer update.
private enum position
{
left=0,
right=1,
center=2
}
var speed : float = 10.0;
var speedIncrement:float=2; //Increment for this craft
var TurnSpeedIncrement:float=1; //Increment for when this craft turns
var rotationSpeed : float = 100.0;
private var m_general:general;
var _cameraFP:Camera = null;
var _cameraWV:Camera = null;
var getreadyText:TextMesh;
var timer: float = -2; // set duration time in seconds in the Inspecto
//Timer
private var startTime;
private var restSeconds:int;
private var roundedRestSeconds:int;
private var displaySeconds:int;
private var displayMinutes:int;
private var m_position:position;
var countDownSeconds:int=120;
function Awake(){
m_position=position.center;
startTime=Time.time;
m_general.currentSystemState=m_general.systemState.PAUSED;
m_position=position.center;
general.StartUpText=0;
/*var guiTime=Time.time+startTime;
//m_position=position.center;
restSeconds=countDownSeconds-(guiTime);
m_general.p_timer=guiTime;*/
}
//Game rendering
function OnGUI(){
}
function Start () {
_cameraFP = GameObject.Find(“MainCamera”).camera;
if (_cameraFP == null)
Debug.Log(“Start(): First Person Camera not found”);
_cameraWV = GameObject.Find(“earthlingMainCamera”).camera;
if (_cameraWV == null)
Debug.Log(“Start(): Wide View Camera not found”);
//SelectCamera(0);
}
function Update () {
var bolEntered:boolean;
var guiTime=Time.time+startTime;
//m_position=position.center;
restSeconds=countDownSeconds-(guiTime);
m_general.p_timer=guiTime;
bolEntered=false;
if(m_general.currentSystemState==1)
{
var xRotation:int;
xRotation=0;
//Keyboard Input
if(Input.GetKeyDown(“up”))
{
speed+=speedIncrement;
//m_general.currentSystemState=0;
}
if(Input.GetKeyDown(“down”))
{
speed+=speedIncrement;
//m_general.currentSystemState=0;
}
if(Input.GetKeyDown(“left”))
{
/speed-=TurnSpeedIncrement;
rotationSpeed+=TurnSpeedIncrement;
xRotation=-30;/
if(m_position!=position.left)
{
speed-=TurnSpeedIncrement;
rotationSpeed+=TurnSpeedIncrement;
xRotation=90;
bolEntered=true;
if(m_position==position.center)
{
m_position=position.left;
Debug.Log (“left”);
}
else
{
if(m_position==position.right)
{
m_position=position.center;
Debug.Log (“center”);
}
}
}
else
{
m_position=position.left;
bolEntered=false;
xRotation=0;
Debug.Log (“left”);
}
//transform.Translate (0, 0, xRotation*3);
//m_general.currentSystemState=0;
}
if(Input.GetKeyDown(“right”))
{
/speed-=TurnSpeedIncrement;
rotationSpeed+=TurnSpeedIncrement;
xRotation=30;/
if(m_position==position.right)
{
m_position=position.right;
bolEntered=false;
xRotation=0;
Debug.Log (“right”);
}
else
{
speed-=TurnSpeedIncrement;
rotationSpeed+=TurnSpeedIncrement;
xRotation=-90;
bolEntered=true;
if(m_position==position.center)
{
m_position=position.right;
Debug.Log (“right”);
}
else
{
if(m_position==position.left)
{
m_position=position.center;
Debug.Log (“center”);
}
}
}
//transform.Translate (0, 0, xRotation*3);
//m_general.currentSystemState=0;
}
if(speed<0)
speed=0;
// Get the horizontal and vertical axis.
// By default they are mapped to the arrow keys.
// The value is in the range -1 to 1
var translation : float = Input.GetAxis (“Vertical”) * speed;
var rotation : float = Input.GetAxis (“Horizontal”) * rotationSpeed;
// Make it move 10 meters per second instead of 10 meters per frame…
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
// Move translation along the object’s z-axis
transform.Translate (0, 0, translation);
// Rotate around our y-axis
//transform.Rotate (0, rotation+xRotation,rotation);
if(bolEntered==true)
{
transform.Rotate (0, 0,xRotation);
}
if(m_position==position.left)
{
transform.Rotate (rotation, 0,0);
}
if(m_position==position.right)
{
rotation*=-1;
transform.Rotate (rotation, 0,0);
}
}
}
function SelectCamera(cameraIndex:int)
{
if (_cameraFP != null)
_cameraFP.camera.enabled = (cameraIndex == 0);
if (_cameraWV != null)
_cameraWV.camera.enabled = (cameraIndex == 1);
}
function theTime(){
timer += Time.deltaTime;
if ((timer > 0) (timer <2)){
general.StartUpText=1;
}
else if ((timer > 2) (timer <4)){
general.StartUpText=2;
m_general.currentSystemState=1;
}
else if ((timer > 4) (timer <6)){
general.StartUpText=3;
m_general.currentSystemState=1;
}
else if ((timer > 6) (timer <8)){
general.StartUpText=4;
m_general.currentSystemState=1;
} else {
getreadyText.text=“dd”;
guiText.text = “TIME OVER\nPress X to restart”;
}
}
function toDo(){
switch(m_general.p_timer)
{
case 9:
general.CameraControl=1;
m_general.currentSystemState=1;
break;
}
}