• 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 /
This question was closed Dec 10, 2016 at 05:57 AM by NovaDrox for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by NovaDrox · Dec 05, 2016 at 07:29 AM · waitforsecondsinvisiblevisible

My Object Won't Turn Visible Again

The problem is for me is that I have the correct code and I set it up right, but it won't turn visible again. It can go invisible, but can't go visible again.

using UnityEngine; using System.Collections;

public class Ammo : MonoBehaviour {

 public float WaitTime;

 public GameObject Ammo_Box;


 private int Count_Ammo;

 // Use this for initialization
 void Start()
 {

     StartCoroutine("MoreAmmo");

     Count_Ammo = 0;
     
 }

   

 // Update is called once per frame
 public void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         this.gameObject.SetActive(false);

         

     }

 }

 IEnumerator MoreAmmo()
 {
     if (Ammo_Box)
     {

         
         yield return new WaitForSeconds(WaitTime);
        
         Ammo_Box.SetActive(false);
         
         yield return new WaitForSeconds(WaitTime);
        
         Ammo_Box.SetActive(true);
        

     }

 }

}

I don't know what it is going wrong. I am also trying to create a if statement so when it it triggered and goes invisible, I want the counter to start and after the time is up, then goes visible again.

Comment
Add comment
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

  • Sort: 
avatar image
1

Answer by Yoshinator2 · Dec 05, 2016 at 04:42 PM

Once you disable an object, all its components get disabled too. So, whenever you disable the object, the attached script is no longer running, which is why your code isn't going through. Create another script on an empty game object and call it LevelManager or something of the such, and then have the gameobject that is being disabled start a function in the LevelManager that will run your code that will enable the object again when needed. If this helped please accept the answer!

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 NovaDrox · Dec 05, 2016 at 10:04 PM 0
Share

Yeah, thank you for the help. I feel bad now that I took time away from you. Once I posted this question, I found out the answer from another recourse and I learned that way. So, thank you again. ^^

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Invisible objects renderer disable? How to stop this? 0 Answers

Mouse over make object Visible 2 Answers

get object invisible for couple seconds and get visible again 1 Answer

Converting C# to JS: rendering a mesh 1 Answer

how GUIText get visible? 2 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