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 missypooh · Mar 20, 2012 at 06:33 AM · scriptingbasics

Make gameobject inactive and then after sometime make it active again

Player will collect the radical gameobject. After that they will need to select the correct option. If they select the wrong answer, i will have to make the hit.gameObject.active = true; the object did reappear but when player try to collide with the gameobject, hit.gameObject.active = false is not working. I feel that my logic quite weird, but i not sure how to tackle the question.

 if(hit.gameObject.tag == "rad1b") 
         {
             //Destroy(hit.gameObject);
             hit.gameObject.active = false;
             //radicals[1].active = false;
             // play a sound clip at the exact position we hit the object
             AudioSource.PlayClipAtPoint(hitSound, transform.position);
             //networkView.RPC("removeDiamond", RPCMode.AllBuffered);
             
             rad1b = true;
             print("rad1b");
         }

So basically the reactivate of gameObject is done at the openableDoor.js script. And i didn't do anything to the player script.

 function showChoices()// attached to the gameObject door
 {
 if(choice)
 {
     if(wrong)
         GUI.Label (Rect (20, 30, 300, 60), "Wrong Option!");
     
     if(MoveAround.rad1a)
     {
         //~ // You may put a label to show a message to the player
         if(GUI.Button(Rect(20,44,100,120), R01a, ""))
         {
             audio.PlayOneShot(correctSound);
             print("rad01a");
             correct = true;
         }
     }
     
     if(MoveAround.rad1b) 
     {
         if(GUI.Button(Rect(125,44,100,120), R01b, ""))
         {
             audio.PlayOneShot(wrongSound);
             print("rad01b");
             wrong = true;
             //R01bb.active = true;    // Set gameobject to active
         }
     }

     function Update(){
     if(wrong)
     {
         if(MoveAround.rad1a) // if this true mean that it already destroy, need to respawn the object
         {
             radical[0].active = true;
             r1a = true;
         }
         if(MoveAround.rad1b)
         {
             radical[1].active = true;
             r1b = true;
         }
         if(MoveAround.rad1c)
         {
             radical[2].active = true;
             r1c = true;
         }
         if(MoveAround.rad1d)
         {
             radical[3].active = true;
             r1d = true;
         }
         if(MoveAround.rad1e)
         {
             radical[4].active = true;
             r1e = true;
         }
         if(MoveAround.rad1f)
         {
             radical[5].active = true;
             r1f = true;
         }
     }
     
     if(wrong)
     {
         MoveAround.rad1a = false;
         MoveAround.rad1b = false;
         MoveAround.rad1c = false;
         MoveAround.rad1d = false;
         MoveAround.rad1e = false;
         MoveAround.rad1f = false;
     }
 }

*Edit the code snippet

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 Meltdown · Mar 20, 2012 at 06:47 AM 0
Share

@fafase enabled is not a property of gameObject

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Meltdown · Mar 20, 2012 at 06:49 AM

MissyPooh I'd suggest using a co-routine with a time delay to reactivate your object. It really is quite simple to use, follow the instructions/code samples on the linked page.

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 missypooh · Mar 20, 2012 at 01:48 PM 0
Share

function Update() { StartCoroutine(reloadObject()); }

function reloadObject() { hit.gameObject.active = true; }

it is something like that??

avatar image
0

Answer by aldonaletto · Mar 20, 2012 at 02:57 PM

The problem doesn't seem to be in the code you've posted. Maybe another part of the code isn't being reset when you re-activate the object. Could the variable rad1f be the culprit? If you don't set it to false again, some other part of the code will "think" the radical was already collected.

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 missypooh · Mar 20, 2012 at 03:06 PM 0
Share

hello, i have add in more code snippet. Would appreciate if you could take alook what is wrong with the code snippet. Basically the gameObject did reappear. Just that when the player going to collide with it the second time, it does not do this (hit.gameObject.active = false)

avatar image aldonaletto · Mar 22, 2012 at 03:20 AM 0
Share

The code has some weird things: GUI.Button, GUI.Label and any other GUI functions must be used in the OnGUI event, but they are in showChoices - unless you call showChoices in OnGUI, you will get lots of Null Reference errors. Another weird thing: Update seems to be declared inside showChoices - is it a typo?

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

6 People are following this question.

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

Related Questions

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

Not every Class in the API is derived from the "Object"-Class, so what are they? 2 Answers

Script to teleport player (Beginner here) 0 Answers

How to learn scripting without Unity 3 Answers

Difference between while loop and dowhileloop? 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