- Home /
Animator with Collider (2D)
Hi, all. I've searched the forums on this with no luck, so...
In a C# script, I create a GameObject to which I add an empty SpriteRenderer (null Sprite) and an Animator (with a RuntimeAnimatorController) followed by a BoxCollider2D.
(My aim is to have a number of generated animators that can interact with mouse events)
However, since the Sprite is null, the renderer bounds are 0, hence the collider bounds are 0, thus the OnMouseEnter/Exit/Click function isn't triggered.
Therefore, my question is as follows:
Is there a way to get the bounds of the animator so I can apply it to the collider (I noticed the old animation component has localBounds, but Animator does not appear to have anything similar); Or
Is it possible to get the first frame/sprite from the animator so I can assign it to the sprite renderer to give the GameObject/Collider size and substance; Or
Is there some other way to give the collider a relevant size?
If not, I may need to provide a Sprite (or size) to the script along with the RuntimeAnimatorController(s), but with potentially many animators, I'd much prefer to extract the information from a single input.
Thanks in advance...
Your answer
Follow this Question
Related Questions
Animation in unity 2 Answers
Animations on a gun 1 Answer
Can I make animations snap to a frame? 1 Answer
Moving textures over a model 1 Answer
Animation from actual position instead of animation starting position 0 Answers