- Home /
trying to use lists to pickup an object and put in inventory
I am very new to C# programming and Unity, and currently am trying to teach myself about GUI and lists. I understand how lists work very well, but I am struggling to figure out how to say them and use them in code; all the tutorials I find are rather esoteric and over my head.
What I want to do is very simple; when I walk over an object, I want an icon to appear in an inventory indicating it has been picked up--but I want to do this using lists. I am unsure whether I can use GUItextures or if I should make the GUI in code. If anyone can show me a script that can do this or point to a tutorial that explains how to do this, I would appreciate you sharing it.
This is the script I have so far for my pickupobjects: using UnityEngine; using System.Collections;
public class CoinDestroy : MonoBehaviour {
public AudioClip pickupSound;
private Vector3 spawn;
// Use this for initialization
void Start () {
spawn = transform.position;
}
void OnTriggerEnter(Collider other){
AudioSource.PlayClipAtPoint(pickupSound, spawn);
Destroy(gameObject);
}
// Update is called once per frame
void Update () {
}
}
Answer by christoph_r · May 27, 2014 at 09:56 PM
While that's not something extremely difficult to do, I still wouldn't say it's "very simple", especially for a beginner. You should probaby also break it down into multiple scripts, for example one for detecting inventory objects on the ground, one for inventory management and then one for the GUI. Having said that, I'm not quite sure where exactly lists would come in here... Do you want your inventory to be a list?
Yes. I've been assigned this project in my Unity class, but we aren't taught how to go about executing it. It's not a very good class.
I'm guessing all of the objects that are to be picked up (I've made 5 differently colored coins) are supposed to go into a list that the GUI is supposed to reference, and when they are touched, the GUI looks at which one is touched and displays it in the inventory.