- Home /
Changing font size over time
Hello everyone.
I would like my score font to 'pop' every time a point is scored.
I would like to understand what is wrong with my logic here. As I understand this it would be possible to use time.deltaTime for this.
void Update () {
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0))
{
audio.Play();
score++;
PopUp();
}
}
void PopUp()
{
myStyle.fontSize = 100 - 10*Time.deltaTime;
myStyle2.fontSize = 100 - 10*Time.deltaTime;
}
Answer by Fornoreason1000 · Oct 25, 2014 at 01:54 PM
why do you put a debug statement in your pop up method? then you know howmany times it is called....
the logic you are using is whenever you press the mouse/key your font decreases , a pop is a increase then a decrease in size(at least from what I understand) and needs to be run in Coroutine so it can be done over a period of time`enter code here`
void Update () {
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0))
{
audio.Play();
score++;
StartCoroutine(PopUp()); //you must use StartCoroutine to run Coroutines
}
}
//Coroutines must return an IEnumerator
IEnumerator PopUp()
{
myStyle.fontSize = 90;
myStyle2.fontSize = 90;
//Waits 10 frames , play with this
for(int framecnt = 0; framecnt < 10; framecnt++) {
yield return new WaitForEndOfFrame();
}
myStyle.fontSize = 100;
myStyle2.fontSize = 100;
}
Thank you so much it works perfectly. $$anonymous$$aking my game look slick.
You are welcome, glad that we sorted this out
If you want to.. you can make it Grow into the pop, to make it a bit smoother ins$$anonymous$$d of popping instantly... It's almost exactly the same code as in my answer ins$$anonymous$$d there are two for loops and you subtract/add from the font size in each loop waiting a frame(or a Tim in seconds) after each subtraction or addition...
Thanks for the input.
The score will increment very quickly, I feel like the user will not see the smoother popping.
Thank you again. The unity community is AWESO$$anonymous$$$$anonymous$$
Your answer
![](https://koobas.hobune.stream/wayback/20220613165922im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Playing clock ticking sound 1 Answer