- Home /
Is it possible to use a random spawn position as a keyframe in an animation?
I'm working on a 2d game and here's what I've got. I'm spawning some prefabs right outside of the camera view. What I would like to do is to be able to use that spawn position, as a position keyframe in an animation. This way I can move the animation to the location on the screen that I want.
The way I have things setup now, my objects spawn location depends on the size of the device's screen. I get the world point by using ViewportToWorldPoint and then subtract the sprite extents so the object spawn immediately off the screen. I have also defined dynamic screen locations (depending on device screen size), that I would like to move my the gameObject to.
Ideally I would like to be able to use Mecanim to interpolate from my spawn point to the end point.
Is this even possible with Mecanim? If so, can you point me in the right direction? Thanks!
Have you tried using the event system? Both mecanim animations and the unity Animation window allow you to specify a specific key frame to handle an event. From that event you can do anything you want in code
Since you dont know the spawn position, on a specific key frame you would trigger an event that would look for the position and update whatever you need to update
I am not sure what exactly you are animating but it sounds like you want to position an object where youve spawned an enemy and play an existing animation? If that is the case you could simply make your object a child of an empty game object. $$anonymous$$ove that empty game object to the spawn location and your animation will be playing in "local" space
Unless what you are asking is if you can update an animations data at runtime. I dont know about that
What I'm trying to do is spawn an object off of the screen and have it slide on to the screen to a specific point. I have calculated the specific point based on the screen size. I also have calculated the final resting point of the sprite based on the screen size.
I think I can make it work through the event system. I was just wondering if there was a way to override the transform of the Animation window so that I can control moving the position of the gameObject through mecanim.