|
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?
(comments are locked)
|
|
This is what I got for the script you gave me: 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); } }
function Start(){ player = GameObject.FindWithTag("Player"); } function Update(){ if(Input.GetButtonDown("Fire2")){ player.gameObject.animation.Play("Aim-FIRE!"); } } This is the error I got: Assets/fire.js(19,10): BCE0089: Type 'fire' already has a definition for 'Update()'. Im sorry, but i'm a nooby at scripting. it's because you have 2 functions of the same name. put player.gameObject.animation.Play("Aim-FIRE!"); into your update function and put player = GameObject.FindWithTag("Player"); into your start function, you then delete the functions that are unused. hope you can understand this :P
Mar 14 '11 at 12:23 AM
MonkeyAssassin8
(comments are locked)
|
Thanks, I'll try that.
Mar 13 '11 at 05:09 PM
Sajid 1
(comments are locked)
|
|
I think you just need to add an 'Animation' Component from the Component Menu onto the Spawnpoint GameObject. No animation component = no animation playing. ;)
(comments are locked)
|
