Hey all,
I now this is probably a pretty silly question, but I’ve been tampering with this for hours now, and it simply won’t do as I want it to.
I know a bit of Javascript, but i’m still pretty new.
What the code is meant to do is add a score to a GUI-text when the one of the player’s 2 colliders hit the object which has the script attached.
Problem is… It works when I hit the first object, and my score reaches 1, but then whenever i hit the other objects with the script attached - nothing happens to the score.
Heres my code:
var PlayerCar1 : Transform;
var PlayerCar2 : Transform;
var scoreText:GUIText;
var score:int;
var value:int;
function Start() {
ctrl = GetComponent(CharacterController);
}
function OnControllerColliderHit(collision: ControllerColliderHit){
if (collision.transform == PlayerCar1) {
score += value;
scoreText.text = "KILLS:" + score;
}
if (collision.transform == PlayerCar2) {
score += value;
scoreText.text = "KILLS:" + score;
}
}
I really hope someone is willing to help me understand what I’m doing wrong here.XD
Lasse B.