- Home /
Collision and score
I have this script that contains my score, this script was downloaded from a tutorial and comes with the action of pressing the b key and it adds the player 100 points, i want to change that so that when the player collides with the tag Coin it adds up 100 points and then it destroys the abject with the tag Coin. This is the code:
var score1 : GUIText;
var myScore : int = 0;
var myCurScore : int = 500;
function Update () {
score1.text = "Score: " + myScore;
if(myScore < myCurScore) {
myScore += 10;
}
if(Input.GetKeyDown("b")) {
myCurScore += 100;
}
},
Answer by Vereos · Nov 27, 2013 at 06:35 PM
Reading your question, I think you just came here and posted this without trying to do it before. However, from the documentation: OnCollisionEnter()
Just write it down like this:
function OnCollisionEnter(collision : Collision) {
if (collision.collider.name == "Coin")
myCurScore += 100;
}
Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.
yes, but its still not working, i put to the player object and to the Coin object
Your answer
Follow this Question
Related Questions
Is there another way of counting Scores (points) instead of Colliding (destroying) 1 Answer
Help scoring Points In a Jousting game 1 Answer
Scoring (i'm stuck) 3 Answers
Question about Point adding / Destroying after collision. 0 Answers
Modified Roll a Ball Tutorial,Modified Roll a Ball tutorial question 1 Answer