Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by shiranui93 · Oct 28, 2012 at 05:11 PM · colliderfpsscorebullethit

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. }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hvilela · Oct 29, 2012 at 02:31 AM 0
Share

Format your code.

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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;
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Anusha · Oct 29, 2012 at 04:45 AM 0
Share

the code is in c#... let me know if you have any doubts...

avatar image
-1

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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. }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Anusha · Oct 30, 2012 at 10:25 AM 0
Share

void = function int = var

function OnCollisionEnter(other : Collision)

avatar image Anusha · Oct 30, 2012 at 10:26 AM 0
Share

accept the answer if it help you

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges