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 chris 3 · Nov 23, 2010 at 07:57 PM · systempickuppoint

Point System and pickup

Hi I am wondering how you could create a simple point system using a GUI and picking up an object.

Thanks!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jesse Anders · Nov 23, 2010 at 08:29 PM

The simplest answer I can think of is:

  1. Make the score a public static variable so that it can be accessed from anywhere (not necessarily the best choice in terms of software design, but nevertheless probably the most straightforward solution).

  2. Give the items to be picked up colliders, and check the 'is trigger' checkbox for them in the inspector.

  3. Add a script to the player object or the item objects that includes an OnTriggerEnter() function. In this function, check if the other object has the right name/tag/etc. (if necessary), and if it does, increase the score as appropriate and destroy the item object.

  4. Create a script with an OnGUI() function, attach it to some game object or other, and display the score using GUI/GUILayout.Label().

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 chris 3 · Nov 29, 2010 at 04:23 PM 0
Share

Thank you! This is very helpful.

avatar image
0

Answer by tomeromero · Nov 23, 2010 at 09:42 PM

Hi..

This is the main script i have for my score system or point system. Name this script Score.

Then,

-create a sphere.

-add Sphere Collider on sphere

-tag the Sphere as Coin

-add this javascript to your character and your ready to go.

You have a pick up system with score on your screen(GUI).

Thank you.

var score = 0; var scoreText = "Score: 0"; var mySkin : GUISkin;

function OnTriggerEnter( other : Collider ) { Debug.Log("OnTriggerEnter() was called"); if (other.tag == "Coin") { Debug.Log("Other object is a coin"); score += 1; scoreText = "Score: " + score; Debug.Log("Score is now " + score); Destroy(other.gameObject); } }

function OnGUI () { GUI.skin = mySkin; GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString()); }

Comment
Add comment · Show 4 · 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 chris 3 · Nov 29, 2010 at 04:22 PM 0
Share

Thank you for your help!

avatar image jacques 1 · Apr 19, 2011 at 02:15 AM 0
Share

hey im planning on using this, but i want it so that i get if my turret is destroyed could you please help, if you need it here is the script for my turret destruction: var explosion : Transform; function OnTriggerEnter(hit : Collider) //function OnControllerColliderHit(hit : ControllerColliderHit) {
if(hit.gameObject.tag == "wormProjectile") { Destroy(hit.gameObject); var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);

                       Destroy(gameObject);
                 }

}

avatar image fjcym · Mar 29, 2012 at 03:15 AM 0
Share

For this script, I have tried it but the counter doesn't change. How do I fix this? this may help you and me

avatar image munaeem · Oct 06, 2012 at 03:51 PM 0
Share

Your above explanation is clear but the script does not work.

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

1 Person is following this question.

avatar image

Related Questions

Point system for car game 0 Answers

points system with coins 3 Answers

Staring system, problem... 2 Answers

Accessing local system ( File Browser ) 2 Answers

Pickup Counter Script 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