Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 piggywho · Aug 19, 2013 at 02:49 PM · androidbuttonguitexturesetactive

Unable to reactive the game object

Hi, I'm new in Unity, I'm create a plant growing simulation game on android platform. I'm using texture button as my button to trigger a game objects. I was able to set it into inactive state, but unable to reactive it... The following is part of my code in GUI Texture.

 public class FertilizerBTN : MonoBehaviour {
     public static int currTouch = 0; //so other scripts can know what touch is currently on screen
     // Use this for initialization
     public GameObject fer;
     
     void Start () {
         fer =  GameObject.Find("Fertilizers");
         fer.SetActive(false);
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.touches.Length <= 0){
            //if no touches then execute this code
         }
         else //if there is a touch
         {
            //loop through all the the touches on screen
             for(int i = 0; i < Input.touchCount; i++)
             {
                 currTouch = i;
             //executes this code for current touch (i) on screen
                 if(this.guiTexture != null && (this.guiTexture.HitTest(Input.GetTouch(i).position)))
                 {
                  //if current touch hits our guitexture, run this code
                     if(Input.GetTouch(i).phase == TouchPhase.Began)
                     {
                         fer =  GameObject.Find("Fertilizers");
                         fer.SetActive(true);
                         
                           Debug.Log("OnTouchBegan");
                     }
                     if(Input.GetTouch(i).phase == TouchPhase.Ended)
                     {
                         
                          this.SendMessage("OnTouchEnded");
                     }
                     if(Input.GetTouch(i).phase == TouchPhase.Moved)
                     {
                          this.SendMessage("OnTouchMoved");
                     }
                 }
             }
         }
     }
 }

I'm sorry if I'm done some newbie mistakes... Hope to get help soon, please and thank you.

Comment
Add comment · Show 2
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 DaveA · Aug 19, 2013 at 02:50 PM 0
Share

Is this script on the game object called "Fertilizers"?

avatar image piggywho · Aug 19, 2013 at 03:00 PM 0
Share

erm, no, it's only a game object name... It's a must to have a script on the game objects?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Joyrider · Aug 19, 2013 at 03:17 PM

You cannot get an inactive gameObject with the GameObject.Find function. (it is explicitly mentionned in the scripting reference)

Before disabling thoses objects, you should store them in a variable/array, or know of a way to access them through the hierarchy.

Comment
Add comment · Show 2 · 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 DaveA · Aug 19, 2013 at 03:28 PM 0
Share

Right. Just don't do the Find each time. Do it in Start (setting 'fer') then you should be able to de/activate it.

avatar image piggywho · Aug 19, 2013 at 08:16 PM 0
Share

Thanks for the helps, It works ! I cant believe this is the mistake I made...Anyway, much appreciate. =)

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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

how to check if touching an guitexture android 0 Answers

pause and restart button on android 1 Answer

I Need a script for a guitexture enableing a spotlight and play a sound when pressed 1 Answer

GUITexture buttons in Android are too sensitive 1 Answer

Can I assign controls to GUITexture button? 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