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 shay4545 · Aug 19, 2014 at 01:51 PM · spritetimetimescale

Timescale help

I'm making a game where the user taps to start and I have used the script below which works fine, but I have text fading in and out saying "tap to start". The text doesn't show up because the timescale is 0. Does anyone know how to just make the sprite show up but make the rest still frozen? I would really appreciate it.

Script:

 using UnityEngine;
 using System.Collections;
 
 public class TapToStart : MonoBehaviour {
 
     void Start () {
         Time.timeScale = 0;
     }
     
     void Update () {
         if(Input.GetMouseButtonDown(0))
         {
             Time.timeScale = 1;
         }
     }
 }



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 Scribe · Aug 19, 2014 at 01:58 PM 0
Share

As far as I know timeScale is global so you can't set it individually for different scripts/ An alternative might be to create your own global timescale variable which you multiply everything you want paused by. Then you can set that to 0 to effect everything except specific things.

1 Reply

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

Answer by HarshadK · Aug 19, 2014 at 02:04 PM

You can use GUI.Label for your text in this case since OnGUI elements are independent on the timescale and will work even if timescale is set to zero.

And for flashing effect you would need to implement your custom timer which will be independent of timescale (like using system time).

A simple Google search will provide enough information and code snippets.

Comment
Add comment · Show 4 · 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 shay4545 · Aug 19, 2014 at 06:48 PM 0
Share

Thanks for the suggestion, it works, but do you know how to make the GUI Label to fade in and out as my sprite did, and then destroy it when the screen is tapped/mouse is clicked?

avatar image Scribe · Aug 19, 2014 at 08:21 PM 0
Share

Hey Shay! how were you changing the alpha of your old text because you can use Time.realtimeSinceStartup to get a time value to base your alpha on. Here's some code on how you could use it with a GUI.Label as Harshad$$anonymous$$ suggested:

 //Unityscipt (~javascript)
 private var i : int = 0;
 var speed : int = 255;
 var str : String = "This is your text";
 private var colorStr : String;
 
 function Update () {
     i = $$anonymous$$athf.PingPong($$anonymous$$athf.FloorToInt(Time.realtimeSinceStartup*speed), 255);
     colorStr = "<color=#ffffff" + i.ToString("x2") + ">";
 }
 
 function OnGUI(){
     GUI.Label(Rect(0, 0, 1000, 500), colorStr + str + "</color>");
 }


Scribe

avatar image shay4545 · Aug 20, 2014 at 12:05 AM 0
Share

This was the fading code I was using on my sprite:

 using UnityEngine;
 using System.Collections;
 
 public class Fade : $$anonymous$$onoBehaviour {
 
 public float duration = 1.0f;
 public SpriteRenderer sprite;
  
 void Update() {
 float a = $$anonymous$$athf.PingPong (Time.time / duration, 1.0f);
 sprite.color = new Color(1f, 1f, 1f, a);
 }
 }

How would I use your script in csharp? I suck at translating from javascript...

avatar image Scribe · Aug 20, 2014 at 07:42 AM 0
Share

If you are using the most up-to-date version of unity then you can just change line 10 Time.time to Time.unscaledTime

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Time.time explanation. 1 Answer

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

how to pause time when hit an object 0 Answers

Physics behave weirdly after timeScale change 1 Answer

2D movement stutter 4 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