- Home /
Why cant I subtract point from my score?
I have one script for objects that add point value.
AddPoints.js :
var pointsToAdd: int = 100;
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
//add a tag to the player called Player, or just
//replace it with your tag if you already have one
ScoreSystem.myScore += pointsToAdd;
Destroy(gameObject,0.0);
}
}
And I modified that code to make another script for when I want to take points as a penalty for hitting walls.
TakePoints.js
var pointsToTake: int = 100;
function OnCollisionEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
//add a tag to the player called Player, or just
//replace it with your tag if you already have one
ScoreSystem.myScore -= pointsToTake;
//Destroy(gameObject,0.0);
}
}
both use the class Score System
ScoreSystem.js:
static var myScore = 0;
var DelayTime = 0;
function Start(){
myScore = 0;
Invoke("myFunction", DelayTime);
}
function OnGUI(){
GUI.Label(Rect((Screen.width / 2) + 20,10, 200, 30), "Score: " + myScore);
}
for some reason my script for subtracting points will not work. Can anyone tell me what Im doing wrong.
P.S. Take Points uses OnCollisionEnter because adding a Trigger would break my walls.
Answer by meat5000 · Aug 30, 2013 at 10:40 PM
Just to point out the obvious, the difference between the two is
OnTriggerEnter - add score
OnCollisionEnter - subtract score
The solution? Try OnControllerColliderHit instead of OnCollisionEnter as apparently the latter doesnt work on Character Controller
That did not work. I am not using a character controller but a simple script that allows the GameObject or Player to respond to arrow keys.