Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by ahgr123 · Aug 13, 2015 at 03:14 PM · gameobjectscriptingbasicsactive

Deactivating/activating gameobjects on button press

Hi, i am still learning scripting so help would be appreciated.

What i am trying to achieve is:

-when scene starts aaa object is deactivated and bbb activated -THIS WORKS

-when button is pressed i want aaa object activated and bbb deactivated - THIS STILL WORKS

-when button is pressed again i want aaa deactivated again and bbb activated again - player could switch between these infinitely - But that part doesn't work and Unity doesn't give me any errors.

I work with Unityscript.

 #pragma strict
 
 var aaa : GameObject;
 var bbb : GameObject;
 
  
      function Start()
 {
     aaa.SetActive(false);
 }
      
      function Update () 
 
 {  
      
      
      if(Input.GetMouseButtonDown(2)) {
      bbb.SetActive (false);
      aaa.SetActive (true);
      
      }
  
      if(Input.GetMouseButtonDown(2) && bbb.SetActive == false && aaa.SetActive == true) {
      bbb.SetActive (true);
      aaa.SetActive (false);
      
     }
   
         
  }
Comment
Add comment · Show 1
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 ahgr123 · Aug 13, 2015 at 07:04 PM 0
Share

Forgot to mention that script isnt attached to that gameobject so this isnt the case why it diesnt work.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by elitcube · Aug 13, 2015 at 07:23 PM

 #pragma strict
 
 var A : GameObject;
 var B : GameObject;
 
 var On : boolean;
 
 function Update () {
     if (Input.GetKeyDown(KeyCode.O)) {
         if (On == true) {
             On = false;
         } else {
             On = true;
         }
     }
     
     if (On == true) { 
     A.SetActive(true);
     B.SetActive(false);
     } else {
     A.SetActive(false);
     B.SetActive(true);    
     }
 }
Comment
Add comment · 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 ahgr123 · Aug 14, 2015 at 09:15 AM 0
Share

thanks a lot! it works perfectly.

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

25 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 avatar image avatar image avatar image avatar image

Related Questions

activate GameObject dont work 1 Answer

Check if the child of an object is active not working!!! 2 Answers

If you disable a gameobject, does an InvokeRepeating loop end or pause? 3 Answers

How to find Inactive GameObject 16 Answers

gameObject.active still draws object 3 Answers


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