• 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
Question by This-is-Cole · May 27, 2017 at 05:57 PM · framerateinconsistentframeskipping

How can I be sure this text appears on screen for at least one frame?

Here I have some code that flashes some text quickly up on the screen. It is important that it flashes like it does for aesthetic reasons. However, I've had a lot of trouble making it function consistently across computers with different framerates. Obviously, it's going to look slower on computers with slower framerates; there's not much we can do to help that, but it's important that it flashes for at least one frame so that the player has a chance to read it for gameplay purposes. On slower computers, I find the text appears very infrequently or hardly at all. Sometimes the sound plays denoting that the text should flash but it doesn't render for a visible frame. Why is the timing inconsistent across different framerates? And when it does flash, even though tremendously slower than with a high framerate, why does it sometimes miss rendering? How could these things be remedied? If anyone can shed some light on what I'm messing up I appreciate any help! Thanks!

 using UnityEngine;
 using System.Collections;
 using System;
 using UnityEngine.SceneManagement;
 
 public class terminalScreenGlitch : MonoBehaviour {
 
     public string[] possibleTexts;
     public Transform inputField;
     public bool visible = false;
     private Vector3 initPos;
     public float xDis = 1;
     public float yDis = 1;
     public float zDis = 1;
     public float jumpiness = 6;
     public float changeChance = 3;
 
     public float apearChance = 40;
     public int howOftenToTest = 6;
     private bool testAgain = true;
     public float apearTime = 0.2f;
 
     public bool goNow = false;
 
     void Start(){
         initPos = transform.position;
         StartCoroutine (testApear());
     }
 
     void Update()
     {
         if (goNow) {
             StartCoroutine (forceGo());
             goNow = false;
         }
 
         if (testAgain) {
             testAgain = false;
             StartCoroutine(testApear());
         }
 
         if (visible) {
             if (UnityEngine.Random.Range (0, changeChance) <= 1) {
                 inputField.GetComponent<TextMesh> ().text = "> " + possibleTexts [Mathf.RoundToInt (UnityEngine.Random.Range (0.0f, possibleTexts.Length - 1))];
             }
 
             if (UnityEngine.Random.Range (0, jumpiness) <= 1) {
                 transform.position = new Vector3 (initPos.x + UnityEngine.Random.Range (-xDis, xDis), initPos.y + UnityEngine.Random.Range (-yDis, yDis), initPos.z + UnityEngine.Random.Range (-zDis, zDis));
             }
 
         } else {
             inputField.GetComponent<TextMesh> ().text = "";
         }
 
     }
 
     IEnumerator testApear(){
         yield return new WaitForSeconds (howOftenToTest);
         if (UnityEngine.Random.Range (0, apearChance) <= 1) {
             visible = true;
             GetComponent<AudioSource> ().Play ();
             yield return null;
             yield return new WaitForSeconds (apearTime);
             visible = false;
             GetComponent<AudioSource> ().Stop ();
         }
         testAgain = true;
     }
 
     IEnumerator forceGo(){
         visible = true;
         GetComponent<AudioSource> ().Play ();
         yield return new WaitForSeconds (apearTime);
         visible = false;
         GetComponent<AudioSource> ().Stop ();
     }
 
 }
Comment

People who like this

0 Show 0
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

Answer by ShadyProductions · May 28, 2017 at 04:44 PM

In a coroutine you can use yield return new WaitForEndOfFrame();

which will wait until the end of a frame, in here you can put the logic.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

65 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

Related Questions

Are animation clips frame dependant? 0 Answers

Consistent and deterministic replays 0 Answers

Movement is frame-rate dependant despite using delta-time 0 Answers

Significant frame drop when switching to Android platform 1 Answer

How to render YUV file properly in Unity? 0 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