- Home /
Question by
NeilJones313 · Jul 03, 2013 at 07:52 AM ·
collisioncolliderscore
Score not adding up?
Hi god people of unity I have my score code set up so that when the ball hits the wall you get 10 points but its not adding up. Please Help I dont know what you add to make it work? This is the code I have on the ball.
static var score : int = 0;
var guiScore : GUIText;
function Start () {
guiScore.text = "Score: 0";
}
function Awake()
{
rigidbody.AddForce( 5, 5, 0, ForceMode.Impulse);
InvokeRepeating("IncreaseBallVelocity", 3, 3);
InvokeRepeating("UpdateScore", 0.05, 0.05);
}
var levelToLoad : String;
function OnTriggerEnter(hit : Collider)
{
Application.LoadLevel("Menu");
}//END FUNCTION ON THAT SHIT!
function IncreaseBallVelocity()
{
rigidbody.velocity *= 1.05;
Debug.Log("velocity: " + rigidbody.velocity);
}
//Score
function OnCollisionEnter(col : Collision) {
if(col.collider.name == "OuterGate"){
score += 10;
guiScore.text = "Score: " + score.ToString();
print("hit");
}
}
Comment
give it a try: Have a script attached to your wall which has the function OnCollisionEnter and test col.collider.name == "myBall" and see if it works.
Answer by reppiz01 · Jul 03, 2013 at 12:12 PM
just an idea, try to set the score integer NOT to static and see if that helps.
Your answer

Follow this Question
Related Questions
Destroying object when player walks over it 1 Answer
Ignore collision at high velocity. 1 Answer
Trouble with Physics.IgnoreCollision 0 Answers
Unwanted jittery behavior 2 Answers
Colliders in a wall jut out 0 Answers