Hi all I have a problem that I can’t solve.
I have 2 js scripts, the fist one (destroy.js) that destroys gameobjects and the second one that adds 100 poits for object destroyed (Score.js).
I want to call the function addscore() in Score.js when destroy.js kills a object.
destroy.js
#pragma strict
function Start () {
}
public var score : Score;
function Update () {
if(transform.position.y<-10)
{this.Destroy (gameObject);
score = gameObject.GetComponent(Score);
score.GetComponent(Score).addscore();
}
}
Score.js
#pragma strict
public var score :int ;
public var killed : int;
function Start () {
score=0;
}
var destory : GameObject;
function Update () {
}
function addscore()
{
score=score+100;
killed= killed + 1;
Debug.Log("Killed: "+killed+" Score: "+score);
}
function OnGUI()
{
GUI.Label(new Rect(Screen.width-200,Screen.height-20, 100, 20), "Punti: "+score);
}