I’m making a 2.5D platformer and I want to make colectable items (such as coins in Super Mario Bros). In my game, the colectiles are similar to Lums (Rayman).
And I want to make it appear the “score” on screen.
How can I make it work in terms of scripts?
Thanks.
EDIT.
some of the collectibles are similar to lums (rayman). How to make it happen in Unity?
Attach this to your player and make sure to tag your collectable object with the tag collectable and also make sure that you have ticked the “is Trigger” box on your collectables as well.
using UnityEngine;
using System.Collections;
public class collectableDestroy : MonoBehaviour {
private int collected = 0; //Set up a variable to store how many you've collected
public AudioClip collectedSound; //This is the sound that will play after you collect one
//This is the text that displayed how many you've collected in the top left corner
void OnGUI(){
GUI.Label(new Rect(10, 10, 50, 20), "Collected:" + collected);
}
private void OnTriggerEnter(Collider other){ //Checks to see if you've collided with another object
if(other.CompareTag("collectable")){ //checks to see if this object is tagged with "collectable"
audio.PlayOneShot(collectedSound); //plays the sound assigned to collectedSound
collected++; //adds a count of +1 to the collected variable
Destroy(other.gameObject); //destroy's the collectable
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}