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;
}
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 timeenter 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;
}