Ok guys, I have a script attached to an empty called "SpawnPoint". The SpawnPoint is attached to my gun. I want it to play an animation when I press the required key. here is the script:
var prefabBullet:Transform;
var shootforce:float;
function Update ()
{
if(Input.GetButtonDown("Fire2"))
{
var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * shootforce);
}
The firing itself works well enough, but the animation refuses to play. This is the error I get:
MissingComponentException: There is no 'Animation' attached to the "SpawnPoint" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "SpawnPoint". Or your script needs to check if the component is attached before using it.
UnityEngine.Animation.Play (System.String animation)
fire.Update () (at Assets/fire.js:15)
Is there a way to get it to access the script attached to my player?
private var player : GameObject;
function Start(){
player = GameObject.FindWithTag("Player");
}
function Update(){
if(Input.GetButtonDown("Fire2")){
player.gameObject.animation.Play("Aim-FIRE!");
}
}
I think you just need to add an 'Animation' Component from the Component Menu onto the Spawnpoint GameObject. No animation component = no animation playing. ;)