Starting an Animation from an Instantiated Object
I have a script for a side scrolling character, moving to the right at a constant rate. The character has a firing option through the left control, and the bullet instantiates and destroys just fine, but I want the bullet to use the animation I made for it as it flies.
Here's my base script for the bullet
if (Input.GetKeyDown(KeyCode.LeftControl) && Time.time > fireGap)
{
fireGap = Time.time - fireRate;
GameObject my_projectile = (GameObject)Instantiate(Resources.Load("bulletSprite"), new Vector2(GetComponent<Rigidbody2D>().position.x + .5f, GetComponent<Rigidbody2D>().position.y), Quaternion.identity);
my_projectile.GetComponent<Rigidbody2D>().AddForce(bulletSpeed, ForceMode2D.Impulse);
if (Time.time > fireRate)
{
SpriteRenderer.Destroy(my_projectile, 10f * ammoSpawn);
}
I've tried using my_projectile.GetComponent().Play to try and force the animation I have attached to the bullet prefab to play, but it never changes anything. I've tried switching to Animator instead of Animation, to no avail either. Any suggestions or guidance would be greatly appreciated.
JG
Your answer
Follow this Question
Related Questions
Animation location problem! 0 Answers
Unity 2D : C# : Animation : CS1061 : Animation does not contain definition for SetFloat.. 1 Answer
Help with making interactive text animation for a 2D game 0 Answers
,Non-working animation - simple fix 0 Answers
How to add alternate idle directions to a top-down game 0 Answers