- Home /
Scoring system based on time remaining and targets hit
Hi, I need help creating a score system on a unity FPS game that I am creating.
The problem is that I want the different targets to be worth a different amount of points but at the same time I want the amount of points you get from hitting the target dependant on where on the target you hit, like if you hit the target in the middle you get more points. I think this will be done with box colliders but I'm not sure. I then want the score system at the end of the game to convert the time remaining into points which can be added to the points from hitting the targets in game.
Any ideas how this could be done? I've attempted many times here's what I have.
static var score: int = 0;
function OnCollisionEnter(hit : Collision){ if (hit.gameObject.tag == "target1" || "target2" || "target3"){ //if targets 01, 04, 07 are hit, they will add amount "X" to the score system. Debug.Log ("Congrats Hit add to score!"); score+=100; //GUIScore.text = score.ToString(); //shows score. GameObject.Destroy(hit.gameobject); //destroys game object upon being hit. }
Answer by Anusha · Oct 29, 2012 at 04:44 AM
void OnCollisionEnter(Collision other)
{
switch(other.transform.tag)
{
case "target1": score+=100; Destroy(other.gameobject);
break;
case "target2": score+=200; Destroy(other.gameobject);
break;
case "target3": score+=300; Destroy(other.gameobject);
break;
}
}
//call at the end of game
void EndGame()
{
int bonus = timeRemaining * 5;
score = score+bonus;
}
the code is in c#... let me know if you have any doubts...
Answer by shiranui93 · Oct 31, 2012 at 09:35 PM
Thanks alot, it was a great answer except now - it immediately deletes the targets 2 and 3 on screen as soon as the player plays the game - meaning they already have some score. Is the a way I can make the score vslue appear on the screen so the player knows there actual score?
Answer by shiranui93 · Oct 29, 2012 at 04:43 AM
It was but this anwser box wouldn't let me edit it properly.
static var score: int = 0;
function OnCollisionEnter(hit : Collision){ if (hit.gameObject.tag == "target1" || "target2" || "target3"){ //if targets 01, 04, 07 are hit, they will add amount "X" to the score system.
Debug.Log ("Congrats Hit add to score!"); score+=100; //GUIScore.text = score.ToString(); //shows score. GameObject.Destroy(hit.gameobject); //destroys game object upon being hit. }
Answer by shiranui93 · Oct 29, 2012 at 10:10 AM
If I was to change it into Javascript, is it a matter of changing void into var?
void = function int = var
function OnCollisionEnter(other : Collision)
Your answer
Follow this Question
Related Questions
bullet hit effect material color be based off the object hit? 0 Answers
Hit distance Change light range 1 Answer
Bullet Damage on different Limbs 1 Answer
collider doesnt react to script 0 Answers
Hit collider problem 1 Answer