Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 naiemali1171987 · May 19, 2019 at 05:27 PM · gameobjectdisableboolenabletimer-script

Bool activate/de-activate on timer C#

Hello there. I have a script here that I don't know how to get working anymore. I've had to go back to this numerous times and completely lost with what I was doing. (Still very new to coding).

Here's my script.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BoolTRUEOnTimer : MonoBehaviour
 {
     public GameObject objectToActivate;
     public int TimeBeforeActivate;
     public int TimeBeforeDisable;
 
     private void Start()
     {
         StartCoroutine(ActivationRoutine());
     }
 
     public IEnumerator ActivationRoutine()
     {
         //Wait for 14 secs.
         yield return new WaitForSeconds(8);
 
         //Turn My game object that is set to false(off) to True(on).
         objectToActivate.SetActive(true);
 
         //Turn the Game Oject back off after 1 sec.
         yield return new WaitForSeconds(15);
 
         //Game object will turn off
         objectToActivate.SetActive(false);
     }
 }


So for the time before activate and time before disable I need it to be public so i can use this on different objects but if you can link them to of course objectToActivate it would be most helpful. Also I forgot to mention, could you get it to disable the gameobject when you play then have it enable on the desired time?

Comment
Add comment · Show 6
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 Magso · May 19, 2019 at 11:32 PM 0
Share

This code would work, what are you wanting to do with it? You are referencing a gameObject with objectToActivate so you can disable and enable it at will.

avatar image naiemali1171987 Magso · May 20, 2019 at 07:06 PM 0
Share

Yes. I need the functions to be public. So I can use the script for more than one thing.

avatar image naiemali1171987 Magso · May 20, 2019 at 07:21 PM 0
Share

I'm trying to port a game. Halo. Halo combat evolved anniversary to android, i'm also trying to do one of the missions but I can't without having this script ;'(

https://www.youtube.com/watch?v=mkiAtH0-foI

avatar image jojizaidi · May 20, 2019 at 07:22 AM 0
Share

In your start function you can just do : objectToActivate.SetActive(false) This will make sure the object is deactivated when the game starts.

In your co-routine if you just need to flash the object

 public IEnumerator ActivationRoutine()
      {
          //Wait for 14 secs.
          yield return new WaitForSeconds(14);
  
          //Turn $$anonymous$$y game object that is set to false(off) to True(on).
          objectToActivate.SetActive(true);
  
          //Turn the Game Oject back off after 1 sec.
          yield return new WaitForSeconds(1);
  
          //Game object will turn off
          objectToActivate.SetActive(false);
      }
avatar image naiemali1171987 jojizaidi · May 20, 2019 at 07:29 PM 0
Share

Thankyou very very much!!! It works now thankyou very much friend! Thankyou so much for getting it to successfully work!!!!

avatar image jojizaidi naiemali1171987 · May 21, 2019 at 04:49 AM 0
Share

Glad it worked ! :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by naiemali1171987 · May 20, 2019 at 07:34 PM

For anyone who wants to know how to use the script, attach it to an empty gameobject, then in the inspector drag and drop what gameobject you want to enable after a certain time and it should work. Don't attach the script to the object your going to enable because when you start the game that gameobject will disable and enable itself after the time wanted. But the script won't function then because it's on the gameobject that was disabled.

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

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

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

Related Questions

Help With Disabling/Enabling single GameObject 1 Answer

Enable/Disable Game Object With GUI Button 1 Answer

How to disable an array of projectors 2 Answers

how to perform undo action in unity? 2 Answers

Alternatives to GameObject.SetActive(...) 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