• 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 kronicles · Jun 25, 2011 at 07:32 PM · score

Create Simple Score System

Hi everyone! Sorry for making this question even that i found a lot of this.

I've been searching for a script and a simple tutorial how to create a simple score system.

I only want my player to catch some objects and the object disappear and give him points!

I'm really noob on the programming side!

Please, help me!

Comment
Add comment · Show 2
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 NoahConstable · Mar 08, 2014 at 03:27 PM 0
Share

Here's the best way:

JavaScript:

 var myScore : int = 0;
 
 function OnCollisionEnter (other : Collision){
     if (other.gameObject.tag == "PointObject"){
         myScore++;
         Destroy(other.gameObject);
     }
 }

Now, I haven't tested it out yet, but I think it will work. You have to attach this script to the Player object, and tag the "Pickup Point Item" as something, and then rewrite my script where it says "PointObject" to whatever you tagged your pickup object.

If there are any errors or issues, please let me know.

Happy Coding!

Noah.

avatar image FtrGameDev_95 · Apr 05, 2015 at 09:10 AM 0
Share

Hi Noah , i hope you can respond to my doubts, what to do if i want to do something like when the projectile you shot, hit an certain type of enemy and that type of enemy carrying particular score like 20 points. ?

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Anxo · Jun 25, 2011 at 08:18 PM

The best thing you can do is go to learnmesilly.com and do some tutorials. They will go over everything you need to.

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
1

Answer by Wyko · Jun 25, 2011 at 08:22 PM

Once you create the code to make the character catch a ball, use the following code to make the object vanish:

Destroy(*yourGameObject*);

For the scoring, make a script for your character with a public variable for the score. That way you can do this:

 var Score : int = 0;

 function ObjectCaught(theGameObject) {
     Destroy(theGameObject);
     Score++;
 }
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 ProWhiteKyurem · Mar 08, 2014 at 03:15 PM 0
Share

It Not Work FOr me :( I use new verison of untiy

plus type of scirpt I have to use :/

avatar image
0

Answer by Wolfdog · Apr 05, 2015 at 11:25 AM

Add a tag to the collectible object, e.g. "food". Add a trigger collider to the collectible object.

If you want to use PlayerPrefs to keep your score, attach this script to the player:

 void OnTriggerEnter (collider c) {
     if (c.transform.tag == "food") {
         Destroy(c.gameObject);
         addScore(your_score, 10); // add your own score
     }
 }
 
 void addScore(string variable_name, int points_to_add) {
     PlayerPrefs.SetInt(variable_name, PlayerPrefs.GetInt(variable_name) + points_to_add);
 }

If you're fine with a normal variable, attach this script:

 int your_score = 0;
 
 void OnTriggerEnter (collider c) {
      if (c.transform.tag == "food") {
          Destroy(c.gameObject);
          your_score += 10; // add your own score
      }
  }

Make sure that your player also has a trigger collider, and that at least one of the two (player or collectible) has a rigidbody attached.

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 SavaTim · Jan 27, 2019 at 12:20 PM

https://www.youtube.com/watch?v=fWmxoHDbE5c Chek it It Easy and Simple And Free

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

Highscore Save 0 Answers

Scoreboard will not update 1 Answer

Don't destroy script on load 2 Answers

Money System Not Working Please Help!!!! (Code fully commented!) 3 Answers

When should I save data 2 Answers


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