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 Blue-Legs · Apr 01, 2015 at 08:48 AM · animationunity 5collisionanimation script

How play an animation through collision (2D Game)?

Hello everyone! I'm new here!

I need help whit a animation. I wanna the girl from my game eat a food. I'm trying to make a collision between the food and the girl. When collide, the girl will start the animation "eat". My animation is made whit .png images (it's a 2D Game).

I make all the transitions:

alt text

The parameter "eat" is trigger and the transition from "Any State" to "eat" is it:

alt text

The GameObject "girl":

alt text

And the GameObject "food"(the script is here with the name "foodScript"):

alt text

And it's the code from "foodScript" (Java, but no problem with C#):

 #pragma strict
  
 var girl : Animation;
  
 function OnTriggerEnter2D(Other : Collider2D)
 {
      if(Other.gameObject.name == "girl")
      {
          girl.Play("eat");
  
      }
 }

I don't know why my animation doens't start... I 'm in it for two days. I looked for answers but found nothing... So... It's it guys! If anyone can help me, please, do it. I don't know where i'm going wrong. It's Unity 5.0.0f4.

Comment
Add comment · Show 1
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 jakhir1 · Apr 01, 2015 at 12:56 PM 0
Share

If you're going to use OnTriggerEnter then make sure that one of objects collider's IsTrigger is set to true and in the image you've shown you haven't assigned the animation to the girl variable in the inspector.

2 Replies

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

Answer by jakhir1 · Apr 01, 2015 at 02:33 PM

You're using the animator, The code you're using won't work like that. Try this instead.

 var girl : Animator;
 function OnTriggerEnter2D(Other : Collider2D)
 {
 
     if(Other.gameObject.name == "girl")
     {
         girl.SetTrigger("NameOfTrigger");
     }
 }
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 Blue-Legs · Apr 02, 2015 at 06:49 PM 0
Share

thank you! it works fine! :D

avatar image
1

Answer by Notter · Apr 01, 2015 at 02:24 PM

You need to use the Animator for the girl, and then activate it's trigger. not just tell the animation "play".

like this:

 public Animator GirlAnimator;
 
 GirlAnimator.SetTrigger("eat");
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Animate gameobject when collided with another gameobject using VRTK 0 Answers

How to run my jump animation in unity3d? 0 Answers

How to loop unity?JS 3 Answers

How do I make animation transitions a one-way street? 1 Answer

Export Animations From Unity3D into Blender? 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