- Home /
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!
Answer by Jesse Anders · Nov 23, 2010 at 08:29 PM
The simplest answer I can think of is:
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).
Give the items to be picked up colliders, and check the 'is trigger' checkbox for them in the inspector.
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.
Create a script with an OnGUI() function, attach it to some game object or other, and display the score using GUI/GUILayout.Label().
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()); }
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);
}
}
For this script, I have tried it but the counter doesn't change. How do I fix this? this may help you and me
Your above explanation is clear but the script does not work.
Your answer
Follow this Question
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