Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 boko52 · Dec 06, 2012 at 05:43 PM · animationtriggerprojectile

Unable to trigger animation with projectile

Hey guys i'm currently having a bit of trouble with some script. Any help will be hugely appreciated. I'm new to Unity and scripting so It might just be a basic error.

Right so what I'm trying to do is have a switch which is out of reach of the player, the player has to use their projectile to hit the switch which activates an animation to open a bridge.

I Keep getting an error, something on the lines of: missing component exception: there is no "animation" attatched to the "projectile" game object

as another note, the projectiles are under a tag, as players can use different projectiles.

Below is my code:

 var Bridge2 : AnimationClip; 
 
 var bridge : GameObject; 
 
 function OnTriggerEnter (collision : Collider)
 
 {
     if (collision.gameObject.tag == "Projectile")
     {
              collision.animation.Play ("Bridge2"); 
      
     }
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by astorga · Dec 06, 2012 at 06:05 PM

From what I can understand of your code, this script is attached in the switch. In this case, you are trying to animate the "Projectile" GameObject when it hits the switch.

I suggest you to change the "Bridge2" type from "AnimationClip" to "GameObject" (and point here the gameObject that will be animated), and change the line from:

 collision.animation.Play ("Bridge2");

to:

 Bridge2.animation.Play ();
Comment
Add comment · Show 2 · 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 boko52 · Dec 06, 2012 at 07:05 PM 0
Share

Thanks a bunch, followed your instructions and it worked perfectly.

Final code was:

var Bridge2 : GameObject;

function OnTriggerEnter (collision : Collider)

{ if (collision.gameObject.tag == "Projectile") { Bridge2.animation.Play ();

}

}

avatar image boko52 · Dec 06, 2012 at 07:45 PM 0
Share

Thanks a bunch, I followed your instructions and it now works perfectly.

The final code ended up as:

 var Bridge2 : GameObject; 
 
 
 function OnTriggerEnter (collision : Collider)
 
 {
     if (collision.gameObject.tag == "Projectile")
     {
              Bridge2.animation.Play (); 
      
     }
 
 }



Thanks again astorga.

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Activating One Part of An Animation 2 Answers

Can I make animations snap to a frame? 1 Answer

OnTriggerStay2D Breaks When Adding AnimationController 1 Answer

Trouble getting a trigger to activate an animation 2 Answers

Exporting animations from maya to unity 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