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 UnityNeewb · Nov 04, 2011 at 12:02 PM · guihowto

Delaying GUITexture!!!

Hey :) .. How would i put a delay in this.. to go in to more detail i want a delay just before my GuiTexture activates This is the code it all works but i want a delay off like 3 seconds befor it actully activates anybody know how to do this??...

var Aim : boolean = false;

var SnipeTexture : GUITexture;

function Update ()

{

 if(Input.GetMouseButton(1))
 {
    Aim = true;
 }

 if(Input.GetMouseButtonUp(1))

 {
    Aim = false;
 }

 if(SnipeTexture == null)

    return;
 
 if(Aim)
 {
    SnipeTexture.enabled = true;
 }
 if(!Aim)
 {
    SnipeTexture.enabled = false;
 }

}

Thanks.

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 syclamoth · Nov 04, 2011 at 03:13 PM 0
Share

Do you want the delay when it starts as well as when it stops, or just when it starts?

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by andresp · Nov 04, 2011 at 12:21 PM

add this to your code:

// do something
yield WaitForSeconds(3.0); // wait for 3 seconds
// do something more...

Source

EDIT - C# Example:

using UnityEngine; using System.Collections;

public class test : MonoBehaviour {

 bool calledDelay = false;
 bool doneDelay = false;

 IEnumerator Wait(float sec)
 {
     yield return new WaitForSeconds(sec);
     Debug.Log("3 seconds later");
     doneDelay = true;
 }

 void Update () {
     if (doneDelay)
         Debug.Log("Do something");
     else if (!calledDelay)
     {
         calledDelay = true;
         StartCoroutine(Wait(3f));
     }
 }

}

Comment
Add comment · Show 8 · 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 UnityNeewb · Nov 04, 2011 at 02:21 PM 0
Share

Where about :P i have tried this method but i don't know where to put it :P

avatar image andresp · Nov 04, 2011 at 03:02 PM 0
Share

I think you would want it at the beginning of Update() or just before the activation of your GUI script in some other script that activates the GUI object/component.

avatar image benjimazza · Nov 04, 2011 at 03:12 PM 0
Share

Nope doesn't work

avatar image andresp · Nov 04, 2011 at 03:53 PM 0
Share

it works. you can't use it inside Update but you can you use StartCoroutine to start a method that can use yield (just as you can see in the link that I posted).

"Note that you can't use yield from within Update or FixedUpdate, but you can use StartCoroutine to start a function that can."

avatar image syclamoth · Nov 04, 2011 at 03:59 PM 0
Share

You can't use yield from within Update, because that would cause the game to hang for a frame! (which it can't because it would be waiting for the update loop to finish, which itself would be waiting for the update loop to finish.)

Show more comments
avatar image
0

Answer by syclamoth · Nov 04, 2011 at 03:16 PM

 function WaitAndSnipe(bool onOff)
 {
     aim = onOff;
     yield WaitForSeconds(3.0);
     if(aim == onOff)
     {
         SnipeTexture.enabled = onOff;
     }
 }

Then, call it from Update inside of

 if(Input.GetMouseButtonDown(1))
 {
     StartCoroutine(WaitAndSnipe(true));
 }


 if(Input.GetMouseButtonUp(1))
 {
     StartCoroutine(WaitAndSnipe(false));
 }
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 UnityNeewb · Nov 04, 2011 at 04:53 PM 0
Share

i get one error Assets/Scripts/Texture.js(4,28): BCE0043: Unexpected token: onOff. Any Clue ??

avatar image
0

Answer by cj_coimbra · Nov 04, 2011 at 05:45 PM

var Aim : boolean = false;

var repeating : boolean = false;

var lastActivationTime;

var SnipeTexture : GUITexture;

function Update ()

{

if(Input.GetMouseButton(1)) { Aim = true; if (repeating == false) { lastActivationTime = Time.time; repeating = true; } }

if(Input.GetMouseButtonUp(1))

{ Aim = false; repeating = false; }

if(SnipeTexture == null)

return;

if(Aim && (Time.time - lastActivationTime > 3.0)) { SnipeTexture.enabled = true; }

if(!Aim) { SnipeTexture.enabled = false; }

}

Comment
Add comment · Show 5 · 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 UnityNeewb · Nov 04, 2011 at 05:51 PM 0
Share

Hey Thanks for the comment, but there's a problem with this code all this code does is make a counter so that when i hold the R$$anonymous$$B it started counting and it goes on for ever and ever and ever Any ideas ??

avatar image cj_coimbra · Nov 04, 2011 at 05:58 PM 0
Share

Try now, let´s see if it helps !

avatar image UnityNeewb · Nov 04, 2011 at 06:17 PM 0
Share

This works great :) how would i change this code so that ins$$anonymous$$d of the GUITexture it was a camera ??

avatar image cj_coimbra · Nov 04, 2011 at 06:21 PM 0
Share

What do you mean? Switch to another camera?

avatar image UnityNeewb · Nov 04, 2011 at 06:25 PM 0
Share

Yeh :) so basicly ins$$anonymous$$d of the GUITexture been activated in 3 seconds the camera is activated in 3 seconds if that makes sense, so basicly ins$$anonymous$$d of the GUITexture its the camera ??

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

Exiting witha GUI Button 1 Answer

activating a box using a GUI button 1 Answer

Collider Animation 1 Answer

'Mission Complete/Game Over' screen once objective is complete. 1 Answer

GUI Scroll View 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