I need to program a game in which you can pick-up notes. I want to make a class that extends from Cube gameobject and add a variable noteText to it. I am new to unity so I have no idea whatsoever on how to do this. Can someone give me a hint?
You won't extend from cube; you'll create a script (which extends from MonoBehaviour) and then attach it to any object (like a cube).
e.g. (C#)
public class PickupNote : MonoBehaviour
{
public string noteText = "";
public void OnTriggerEnter( Collider col )
{
// check if other object is a player
// e.g. if( col.gameObject.tag == "Player" )
Debug.Log("You picked up a note: " + noteText);
Destroy(gameObject); // kill the pickup object now that you have the note
}
}
Yes but ehmm I want a note with variable text... I want to create like a new note ( var note :PickupNote = new PickupNote("This is a test"); ) Like that..