Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sajid 1 · Mar 12, 2011 at 11:27 PM · animationplayfirespawnpointmissingcomponentexception

Fire Animation Help

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); }

if(Input.GetButtonDown("Fire2"))
{
    animation.Play("Aim-FIRE!");
}

}

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MonkeyAssassin8 · Mar 13, 2011 at 02:09 AM

private var player : GameObject;

function Start(){ player = GameObject.FindWithTag("Player"); }

function Update(){ if(Input.GetButtonDown("Fire2")){ player.gameObject.animation.Play("Aim-FIRE!"); } }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sajid 1 · Mar 13, 2011 at 05:09 PM 0
Share

Thanks, I'll try that.

avatar image
0

Answer by by0log1c · Mar 13, 2011 at 06:23 AM

I think you just need to add an 'Animation' Component from the Component Menu onto the Spawnpoint GameObject. No animation component = no animation playing. ;)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Sajid 1 · Mar 13, 2011 at 05:18 PM

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); } }

private var player : GameObject;

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MonkeyAssassin8 · Mar 14, 2011 at 12:23 AM 0
Share

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Play animation C# 1 Answer

Why is Animation Not Playing in Reverse? 2 Answers

play animation with script 4 Answers

Can the animation editor create local rotational data? 3 Answers

Different animation on each wayPoint 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges