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 TheIrishninjas · Sep 16, 2018 at 05:19 PM · booleanswitchingpitch

Problem with displaying text

Hi guys! So, I'm doing some Unity practice before I return to college and I was just working with music and having text that shows the song name and pitch. I have the song name and the pitch (which can be changed with two in-game buttons) visible for one of the songs ('My Shot') but it doesn't work for the other one ('Wait For It', yes I'm Hamilton trash), the name appears fine, but the pitch only briefly flashes onscreen. If anyone could help with this I would appreciate it! Here are the two scripts that it's handled in:

Switching songs:

 void Start () {
         myShot = true;
         waitForIt = false;
     }
 
     void Update()
     {
         if (myShot == true)
         {
             //main.Pause();
             main.clip = Shot;
             myShot = false;
         }
         if (waitForIt == true)
         {
             //main.Pause();
                 main.clip = Wait;
                 main.Play();
                 waitForIt = false;
             }
         }
     // Update is called once per frame
     void OnTriggerEnter2D (Collider2D other) {
         if(other.tag == "Song")
         {
                 myShot = false;
                 waitForIt = true;
             }
         }
 }


Text stuff:

 void Start()
     {
         pitch = main.pitch;
     }
 
     void Update()
     {
         songText.text = song + " " + "Pitch:" + pitch;
         pitch = main.pitch;
         if (SongSwitch.myShot == true)
         {
             song = "My Shot";
         }
         if (SongSwitch.waitForIt == true)
         {
             song = "Wait For It";
         }
     }
 }
Comment
Add comment · Show 2
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 hexagonius · Sep 16, 2018 at 08:59 PM 0
Share

maybe it just does not fit the text field. What happens if you show only the pitch?

 songText.text = pitch;
avatar image TheIrishninjas hexagonius · Sep 17, 2018 at 11:16 AM 0
Share

I tried what you said and the pitch did show up, but then I tried making the text field bigger and it didn't work. Since posting this question, I've put in a button to return the pitch to 1, and noticed that whenever the pitch is at 1, it shows alongside the song name, but then when I change it, that causes it to flash.

1 Reply

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

Answer by LCStark · Sep 17, 2018 at 12:15 PM

Like hexagonius said, your text is probably too long for the Text element to display properly. To check that, select your text object, find the Horizontal Overflow field in the Inspector (it should be set to Wrap) and set it to Overflow. You will see that even if the text is too long, it will be displayed outside of the text area. You might also want to change the Vertical Overflow, if needed.

The second problem is the way you are displaying the pitch value. It is a float value, so when you simply add it to the string, it displays it precisely, down to several decimal places. Depending on the value of the pitch field, the decimal places number might change, causing the text to flicker if it can't fit in the box. You might want to control the number of decimal places yourself. Instead of "Pitch:" + pitch; try using "Pitch:" + pitch.ToString("F2");. That will limit the amount of decimals to 2.

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 TheIrishninjas · Sep 17, 2018 at 12:24 PM 0
Share

This worked, thanks! Also, thanks for the tip about limiting the amount of decimals, that'll probably be helpful in later projects as well.

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

91 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

Related Questions

How would I make 1 bool true whilst making others false 1 Answer

How to switch between only the weapons that the player currently has 1 Answer

problem on switching gun (a var don't turn true) 0 Answers

Sound volume and pitch based on speed of rigidbody and/or normal object? 1 Answer

How to get a rigidbody's Local Angular Velocity (Yaw, Pitch & Roll) ? 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