I have searched around a bit and found tons of awnsers but nothing that really helped me!
Here is my code:
var Health : int = 50;
var prefabBullet:Transform;
var shootForce:float;
var jump : GameObject;
var smoke : GameObject;
var smoking : int = 20;
var HealthPoint : Texture[];
var SpawnPoints : Transform[];
var Deaths : AudioClip[];
var Jump : AudioClip[];
function Update () {
if(Health <= 0){
var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
death();
Health = 50;
}
if(Health <= smoking)
smoke.active = true;
if(Health >= smoking)
smoke.active = false;
if (Input.GetButtonDown("Jump")){
audio.clip = Jump[0];
audio.Play();
jump.active = true;
}
if (Input.GetButtonUp("Jump")){
audio.clip = Jump[0];
audio.Stop();
jump.active = false;
}
}
function OnCollisionEnter(collision : Collision){
if(collision.gameObject.tag == "Bullet"){
var randDamage = Random.Range(1, 5);
var damage = randDamage;
switch(damage){
case 1:
Health -=1;
break;
case 2:
Health -=2;
break;
case 3:
Health -=3;
break;
case 4:
Health -=4;
break;
case 5:
Health -=5;
break;
}
}
}
function OnTriggerEnter(other : Collider){
if(other.tag == "Health"){
Health += 1*Time.deltaTime;
if(Health >= 50){
Health = 50;
}
}
}
function OnGUI() {
if(Health <= 50){
GUI.DrawTexture(Rect(0.0f,0.0f,Screen.width,Screen.height), HealthPoint[5]);
}
if(Health <= 40){
GUI.DrawTexture(Rect(0.0f,0.0f,Screen.width,Screen.height), HealthPoint[4]);
}
if(Health <= 30){
GUI.DrawTexture(Rect(0.0f,0.0f,Screen.width,Screen.height), HealthPoint[3]);
}
if(Health <= 20){
GUI.DrawTexture(Rect(0.0f,0.0f,Screen.width,Screen.height), HealthPoint[2]);
}
if(Health <= 10){
GUI.DrawTexture(Rect(0.0f,0.0f,Screen.width,Screen.height), HealthPoint[1]);
}
if(Health <= 1){
GUI.DrawTexture(Rect(0.0f,0.0f,Screen.width,Screen.height), HealthPoint[0]);
}
}
function death(){
AudioSource.PlayClipAtPoint(Deaths[ Random.Range(0, Deaths.Length)], transform.position, 2.0f);
i = Random.Range(0, SpawnPoints.Length);
transform.position = SpawnPoints*.position;*
_ transform.rotation = SpawnPoints*.rotation;_
_}*_
Error message: IndexOutOfRangeException: Array index is out of range.
Player.OnGUI () (at Assets/Scripts/Player.js:80)