Instance does not play the animation

I make an instance of a skeleton and I passed the refrence of it as a public gameobject,
but when I play animation for the skeleton nothing happen to it

Here`s my code:

using UnityEngine;
using System.Collections;

public class Game : MonoBehaviour {
	
	Enemy enemy;
	Player player;
	
	public GameObject _Spartan;
	public GameObject _Skeleton;
	
void Start()
	{
		player =(Player) _Spartan.AddComponent ("Player");
Vector3 vec;
		vec.x = 91;
		vec.y= 9.8f;
		vec.z = 157.8f;
		
		Instantiate (_Skeleton,vec,_Skeleton.transform.rotation );
	}
	
	void Update()
	{
player.Move ();
			
			
			if(Input.GetKeyUp("space"))
			{

animation.Play ("attack");
				_Skeleton.animation.Play ("die");
			}
}
	
	

}

1 Answer

1

_Skeleton is your prefab, not the instance. You’re calling a function on an asset, that won’t do anything.

GameObject skelInstance = Instantiate (_Skeleton,vec ... ) as GameObject;
// ...
skelInstance.animation.Play ("die");

Thanks buddy, I did not notice that I should buld an instance to hold the data of the prefab

–