var health1 : Texture2D; //one lives left
var health2 : Texture2D; //two lives left
var health3 : Texture2D; //full health
static var LIVES = 3;
function Update ()
{
switch(LIVES)
{
case 3:
guiTexture.texture = health3;
break;
case 2:
guiTexture.texture = health2;
break;
case 1:
guiTexture.texture = health1;
break;
case 0:
//gameover script here
break;
}
}
var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab: Transform;
private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "fallout")
{
dead = true;
//substract life here
HealthControl.LIVES -=1;
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
}
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0,4,0);
gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
dead = false;
}
}
@script RequireComponent(CharacterController)
After I made this scripts, I get the "The referenced script on this Behaviour is missing! " Warning...