c# - Unity: How to animate a flashing TextMesh (so varying the alpha when the player does something)? -
i have tried retracing steps survival shooter tutorial (create animation clip on property of textmesh, vary alpha, , create state machine), animating alpha property in textmesh.meshrenderer._color object nothing, because object disappears on runtime (even though animator window accepts valid object animate...), , animation window shows object missing when reopen it--so thinking must kind of throwaway color object?
the problem "color" can edit in text mesh object. otherwise, state machine working perfectly; , animation seems playing...just nothing happening...and, said, when reopen animation clip in animation window, property labeled 'missing,' though have not touched respective object.
coming trying do: trying implement flashing label in game (rather on hud) invisible until player gets close, whereupon starts flashing (it control suggestion). maybe textmesh object wrong object; maybe animation process wrong...but think easier answer might go how implement trying do...rather trouble shoot mistake making...
you can animation , through code. go code. coroutines
, lerp
, time.deltatime
type of animation possible in unity. code below blink textmesh when starttextmeshanimation()
called , continue until stoptextmeshanimation()
called. change speed calling changetextmeshanimationspeed()
, passing in speed value. in seconds. 0.2 5f fine.
public textmesh textmesh; public float animspeedinsec = 1f; bool keepanimating = false; private ienumerator anim() { color currentcolor = textmesh.color; color invisiblecolor = textmesh.color; invisiblecolor.a = 0; //set alpha 0 float oldanimspeedinsec = animspeedinsec; float counter = 0; while (keepanimating) { //hide while (counter < oldanimspeedinsec) { if (!keepanimating) { yield break; } //reset counter when speed changed if (oldanimspeedinsec != animspeedinsec) { counter = 0; oldanimspeedinsec = animspeedinsec; } counter += time.deltatime; textmesh.color = color.lerp(currentcolor, invisiblecolor, counter / oldanimspeedinsec); yield return null; } yield return null; //show while (counter > 0) { if (!keepanimating) { yield break; } //reset counter when speed changed if (oldanimspeedinsec != animspeedinsec) { counter = 0; oldanimspeedinsec = animspeedinsec; } counter -= time.deltatime; textmesh.color = color.lerp(currentcolor, invisiblecolor, counter / oldanimspeedinsec); yield return null; } } } //call start animation void starttextmeshanimation() { if (keepanimating) { return; } keepanimating = true; startcoroutine(anim()); } //call change animation speed void changetextmeshanimationspeed(float animspeed) { animspeedinsec = animspeed; } //call stop animation void stoptextmeshanimation() { keepanimating = false; }`
Comments
Post a Comment