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 laurienash · Sep 17, 2013 at 06:27 PM · updateyield

Script wait for 3 seconds before running - stops it working altogether

Hi - I want a pause of 3 seconds before this script starts running.

I've tried this method, and although it doesn't run any errors - it stops the script from working altogether? It seems to have worked for other people on the forums, so I was wondering if anyone knew what I'm doing wrong?

 private var cLight:GameObject;
 var intensitySpeedBlackFirst : float = 0.05;
 var intensitySpeedBlackThird : float = 0.05;
 var intensitySpeedWhiteFirst : float = 0.02;
 var intensitySpeedWhiteThird : float = 0.02;
 public static var IsSwitch:boolean = false;
 private var IsChange:boolean = false;
 var lock = true;
 
 
 
 function Start () {
 
 cLight = gameObject.Find("Lighting");
 yield WaitForSeconds (3);
 lock = false;
 
 }
 
 function Update () {
 if(!lock) {
 
     if(IsSwitch) {
         if(!IsChange) {
             if(SwitchCharacters.check == 0)
             cLight.renderer.material.color.a -=Time.deltaTime*intensitySpeedBlackFirst;
             else
             cLight.renderer.material.color.a -=Time.deltaTime*intensitySpeedBlackThird;
             if(cLight.renderer.material.color.a<=0) {
                 IsChange = true;
                 cLight.renderer.material.color = Color(0,0,0,0);
             }
         }
         else {
             //this is first person controller
             if(SwitchCharacters.check == 0)
             cLight.renderer.material.color.a +=Time.deltaTime*intensitySpeedBlackFirst;
             else
             cLight.renderer.material.color.a +=Time.deltaTime*intensitySpeedBlackThird;
             if(cLight.renderer.material.color.a>=1) {
             //screen goes black
             }
         }
     }
     else {
         if(!IsChange) {
             //this is first person controller
             if(SwitchCharacters.check == 0)
             cLight.renderer.material.color.a +=Time.deltaTime*intensitySpeedWhiteFirst;
             else
             cLight.renderer.material.color.a +=Time.deltaTime*intensitySpeedWhiteThird;
             if(cLight.renderer.material.color.a>=1) {
                 //screen goes white
             }
         }
         else {
             //this is first person controller
             if(SwitchCharacters.check == 0)
             cLight.renderer.material.color.a -=Time.deltaTime*intensitySpeedWhiteFirst;
             else
             cLight.renderer.material.color.a -=Time.deltaTime*intensitySpeedWhiteThird;
             if(cLight.renderer.material.color.a<=0) {
                 IsChange = false;
                 cLight.renderer.material.color = Color(1,1,1,0);
             }
         }
     }
 }
 
 }

Any help would be so much appreciated!

Thanks, Laurien

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

2 Replies

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

Answer by laurienash · Sep 17, 2013 at 07:56 PM

Hi - I've just done it in the cheats way by adding this script to a collider:

 #pragma strict
 
 var lightController : GameObject;
 
 function Start () {
 
 lightController.active =false;
 
 }
 
 function OnTriggerEnter (other:Collider) {
 
  if(other.tag == "Player") {
       lightController.active =false;
       yield WaitForSeconds (3);
       lightController.active = true;
     
     }
 }

Thanks for your help though!

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

Answer by Yokimato · Sep 17, 2013 at 06:51 PM

I can't find the documentation after looking quickly, but I remember trying to make Start() a coroutine and it not working...but as a work around, you call a coroutine from Start like so:

     function Start() {
         cLight = gameObject.Find("Lighting");
         StartCoroutine(SetLock(false));
     }
     function SetLock(status: boolean) {
         yield WaitForSeconds (3);
         lock = status;
     }
Comment
Add comment · Show 3 · 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 laurienash · Sep 17, 2013 at 07:17 PM 0
Share

Hmm - I've tried that, I'm not getting any errors, or anything in the log, but it's not working. If I put if (!lock) { in the update function nothing happens, and if I comment it out it works immediately (just as before) Any ideas?

Here's the updated script:

  var intensitySpeedWhiteFirst : float = 0.02;
     var intensitySpeedWhiteThird : float = 0.02;
     public static var IsSwitch:boolean = false;
     private var IsChange:boolean = false;
     var lock = true;
     
     
     function Start() {
            cLight = gameObject.Find("Lighting");
            StartCoroutine(SetLock(false));
         }
         
         
         function SetLock(status: boolean) {
            yield WaitForSeconds (3);
            lock = status;
         }
     
     
     
     function Update () {
     
     if (!lock) {
         if(IsSwitch) {
             if(!IsChange) {
                 if(SwitchCharacters.check == 0)
                 cLight.renderer.material.color.a -=Time.deltaTime*intensitySpeedBlackFirst;
                 else
                 cLight.renderer.material.color.a -=Time.deltaTime*intensitySpeedBlackThird;
                 if(cLight.renderer.material.color.a<=0) {
                     IsChange = true;
                     cLight.renderer.material.color = Color(0,0,0,0);
                 }
             }
             else {
                 //this is first person controller
                 if(SwitchCharacters.check == 0)
                 cLight.renderer.material.color.a +=Time.deltaTime*intensitySpeedBlackFirst;
                 else
                 cLight.renderer.material.color.a +=Time.deltaTime*intensitySpeedBlackThird;
                 if(cLight.renderer.material.color.a>=1) {
                 //screen goes black
                 }
             }
         }
         else {
             if(!IsChange) {
                 //this is first person controller
                 if(SwitchCharacters.check == 0)
                 cLight.renderer.material.color.a +=Time.deltaTime*intensitySpeedWhiteFirst;
                 else
                 cLight.renderer.material.color.a +=Time.deltaTime*intensitySpeedWhiteThird;
                 if(cLight.renderer.material.color.a>=1) {
                     //screen goes white
                 }
             }
             else {
                 //this is first person controller
                 if(SwitchCharacters.check == 0)
                 cLight.renderer.material.color.a -=Time.deltaTime*intensitySpeedWhiteFirst;
                 else
                 cLight.renderer.material.color.a -=Time.deltaTime*intensitySpeedWhiteThird;
                 if(cLight.renderer.material.color.a<=0) {
                     IsChange = false;
                     cLight.renderer.material.color = Color(1,1,1,0);
                 }
             }
         }
     }
     
     }
avatar image Yokimato · Sep 17, 2013 at 07:25 PM 0
Share

I'm not a "UnityScript" master, only c#...however, the only thing I noticed as different is how you're initializing lock. What if you changed: var lock = true; to: private var lock:boolean = true;

avatar image laurienash · Sep 17, 2013 at 07:57 PM 0
Share

I tried that - but it still acted the same :(

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

16 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

Related Questions

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

Input versus Event 1 Answer

Looping t wo functions until a condition is not met? 1 Answer

Having a script variable update between two objects 1 Answer

Adding XP for each kill 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