• 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
0
Question by Thereddic · Nov 11, 2014 at 10:45 PM · getcomponentgetter

Implementing Setter/Getter

So I've been trying to build an item pick up system in a game, but I've run into a bit of a problem. The system uses two scripts, one to mark the items as held, and another to handle picking up the item itself. The add item to inventory script looks like t$$anonymous$$s

 public void foundItem(int symbolNum){
         //Iterates through all the clue items based off the length of images there are
         //If the itemNum = images[ itemNum - 1] you have found the item
         //Set the item that you have found to isFound = true
         //Set the newly found item image to a visible transpency
         print ("Looking for item# "+symbolNum);
         //If the clue value is the same as symbol value, proceed
         GameObject[] clueSymbolGOs = GameObject.FindGameObjectsWithTag("ClueSymbol");
         //We are now looking for the clueItem i that matches s (symbol number)
         foreach(GameObject clue in clueSymbolGOs){
             if(clue.GetComponent<ClueBehaviour>().getClueSymbol() == symbolNum){
                 print ("Found clue symbol game object # "+ symbolNum);
                 //clue.GetComponent<GUITexture>().texture = symbolHolder;
                 //t$$anonymous$$s.gameObject.GetComponent<GUITexture> ().texture = images[itemNum];
                 clue.GetComponent<ClueBehaviour>().isFound = true;
                 clue.GetComponent<GUITexture>().color = new Color(1f, 1f, 1f, 1f);
             }
         }
     
     }

$$anonymous$$ed, there's more to that script than t$$anonymous$$s, but t$$anonymous$$s is the only part that pertains to what I'm doing. The second script functions by feeding a number to the int symbolNum, allowing the first function to know what to check off as found. The code I have to feed the number looks like t$$anonymous$$s

 void OnTriggerStay2D() {
     if (Input.GetMouseButtonDown (0)) {
         Symbolmatch = (GetComponent<ClueBehaviour>().foundItem(2));
         Destroy (t$$anonymous$$s.gameObject);
         //Find.gameObject("Clue2").GetComponent<ClueBehaviour>().clueSymbol = 2;

         Debug.Log ("clicked");
     }
 }

Looking around has told me that a getter/setter is the best way to make t$$anonymous$$s work, but I don't know how to set one of those up properly, despite looking at a number of example and tutorial videos. Can someone help me get t$$anonymous$$s working?

Comment
Add comment · Show 4
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 gjf · Nov 11, 2014 at 08:28 PM 0
Share
avatar image Thereddic · Nov 11, 2014 at 08:52 PM 0
Share
avatar image gjf · Nov 11, 2014 at 09:26 PM 0
Share
avatar image Thereddic · Nov 11, 2014 at 09:33 PM 0
Share

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Simple question about OnMouseButtonAsUp 1 Answer

Any problems with this script? 1 Answer

Error accessing var from other scripts within project via GetComponent 1 Answer

Object reference not set to an instance of an object 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