• 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
Question by ChicMonster · May 27, 2014 at 09:18 PM · beginnerlistspickup

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 () {
     
     }
 }
 
Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

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?

Comment

People who like this

0 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 ChicMonster · May 27, 2014 at 11:51 PM 0
Share

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.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NullReferenceExeption 1 Answer

An extremely stupid question... I'm a newbie 3 Answers

Creating a list using a list from another script? 1 Answer

Help with adding power ups to game 1 Answer

KeyNotFound Exception when playing. 1 Answer


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