I have the script
var health = 1.0;
var hitsound : AudioClip;
var number = 10.0;
function ApplyDamage (damage : float) {
health -= damage;
SendMessage("CheckHealth");
}
function CheckHealth () {
if (health <= 0) {
Destroy (gameObject);
if (hitsound)
AudioSource.PlayClipAtPoint(hitsound, transform.position);
}
}
function OnGUI () {
GUI.Box (Rect (10,number,110,30), "Enemy health" + Mathf.Round(health));
}
which is an enemy health script, and
public var pause = false;
var player : Transform;
var Player : Transform;
var fullscreen : boolean;
var Pauseskin : GUISkin;
var allObjects : Array;
function Awake () {
allObjects = FindObjectsOfType(GameObject);
fullscreen = Screen.fullScreen;
if (player == null GameObject.FindWithTag("Player"))
player = GameObject.FindWithTag("Player").transform;
if (Player == null GameObject.FindWithTag("MainCamera"))
Player = GameObject.FindWithTag("MainCamera").transform;
}
function Update () {
if (Input.GetButtonDown("Pause")) {
if (pause == false) {
pause = true;
}
}
if (pause == false) {
SendMessage("Unpause");
}
else if (pause == true) {
SendMessage("Pause");
}
if (fullscreen == false) {
Screen.fullScreen = false;
}
else if (fullscreen == true) {
Screen.fullScreen = true;
}
}
function OnGUI () {
if (pause == true) {
GUI.skin = Pauseskin;
GUI.Box (Rect (-5,-5,Screen.width + 10,Screen.height + 10), "Pause");
if (GUI.Button (Rect(Screen.width / 2, Screen.height / 2 + 30,75,50),"Exit")) {
Application.Quit();
}
if (GUI.Button (Rect(Screen.width / 2, Screen.height / 2 - 30,75,50),"Resume")) {
pause = false;
}
GUI.BeginGroup (Rect (Screen.width - 205, 5, 200, 300));
GUI.Box (Rect (0,0,200,300), "Display Settings");
fullscreen = GUI.Toggle (Rect (15,25,150,20), fullscreen, " Full Screen");
GUI.EndGroup ();
}
}
function Pause () {
for (var go : GameObject in allObjects) {
if(go.GetComponent(MouseLook)){
go.GetComponent(MouseLook).enabled = false;
}
}
Time.timeScale = 0;
Screen.lockCursor = false;
}
function Unpause () {
for (var go : GameObject in allObjects) {
if(go.GetComponent(MouseLook)){
go.GetComponent(MouseLook).enabled = true;
}
}
Time.timeScale = 1;
Screen.lockCursor = true;
}
which is a game manager script. the enemy belongs to the array in the game manager script, and when i kill the enemy, it is destroyed, but it gives me an error, because the enemy was a part of the array. how can i solve this by removing the enemy from the array, or is there a way i could add objects only containing mouse look scripts? the function that the script mainly covers is pause menu, and pausing. and that is why i need to disable that script.