- Home /
Score through hiting targets and time based score.
Hi guys I know there are a lot of questions about how to make a scoring system but this is going to be a little different because I need something else then what has already been answered.
What I need is a score system that when I have destroyed one of my targets I get points for doing so the way I destroy targets is by using a gun and shooting bullets at targets to destroy them. There are 2 types of targets one set of targets gives you 10 points and the other targets that are optional gives you 50 points I also need to be able to give points based on time so lets say depending on how many seconds are left give the player an extra 10 points per second; I would also like a system that takes points if you miss a target so lets say minus 10 points every time you miss. Basically I'm creating an FPS where the score is based of targets hit and time. Tbh I need this for my uni assignment and I'm just a little stumped and any help would be really useful so yeah please help. btw I have made a start on the code now I just need your help to finish it :).
// textfield to hold the score and score variable
private var textfield:GUIText;
private var score:int;
function Awake(){
textfield = GameObject.Find("GUI/ScoreCount").GetComponent(GUIText);<br />
score = 0;
UpdateScoreText();
}
function UpdateScoreText(){
// update textfield with score
textfield.text = score.ToString();
}
so yeah please help becauase I'm so close to getting this finished and I just need a bit of help to finish this project of :).
you just need to learn to use Invoke. it is very simple. Go to unityGE$$anonymous$$S.com for a massive explanation
Answer by Anusha · Oct 31, 2012 at 04:47 AM
private var score:int;
function OnCollisionEnter(other : Collision )
{
switch(other.transform.tag)
{
case "10points": score+=10; Destroy(other.gameobject);
break;
case "optinal50": score+=50; Destroy(other.gameobject);
break;
default: score-=10;
break;
}
}
//call at the end of game
function EndGame()
{
var bonus = timeRemaining * 10;
score = score+bonus;
}
ok.. when your bullet hit any other objects other than your targets the switch will go to default, you will know that you have skipped your target and the score gets deducted. tag your normal target "10points", optional targets "optional50", you have call the EndGame() at gameover so the remaining points gets added to score.... the code is in js now.... i have not tested it though. :)
right this is really good thanks unfortunately I'm only allowed to use JavaScript coding in the project so if you can possibly change it to JavaScript coding that would really help :). also for this code could I tag anything that isn't my code as HitBG because I have a terrain and several game objects that are not the targets so if you hit them you will loose points as well. Anyway your answer has been helpful but I do really need it is as JavaScript so if you can do that I would be really grateful :). p.s that's not to say I'm not grateful already cause I am :).
no dont tag rest of the stuff... i will change the code to suit ur requirement....
yay thank you this is really going to help me and thanks for switching it to JavaScript because that's of a lot more use to me. btw how do you list this question as answered.
hi @rogue
look at the TOP and the LEFT of the actual ANSWER. notice there is a number and two "thumb" signs.
notice also a "tick" sign, under the thumbs.
click on that TIC$$anonymous$$ sign.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Game Character manager 0 Answers
FPS Multiplayer Help 1 Answer
infinite runner HELP 1 Answer
Collision detection 2 Answers