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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Dec 18, 2014 at 11:05 PM · collisioncollider

Animation OnTriggerEnter

Hello Unity3D.I have a problem with onTriggerEnter.My problem is that i am trying to make my opponent play different animations depending on the animation that the player is colliding with.For example im trying to make my opponent play a "Fall" animation whenever my character plays a headbutt animation and it collides with the opponent.Which code would be better for this situation? OnCollisionEnter or OnTriggerEnter? If anyone knows how to make it that my opponent play animations depending on the animation that the player hits the opponent with.Can someone please tell me how?I have been stuck all day...

 #pragma strict
 
 var setOnFire : ParticleSystem;
 var player :Transform;
 var speed = 30;
 var pushPower = 2.0;
 var sceneCam : GameObject;
 sceneCam = GameObject.Find("MainCam");
 function Start ()
 {
     setOnFire.Stop();
 }
 
 function OnTriggerEnter (Col : Collider)
 {
 
     if(Col.tag == "Player")
         if(!animation.IsPlaying("Headbutt"))
             if(!animation.IsPlaying("Sidekick"))
                 animation.Play("Hit1");

     sceneCam.transform.position = Vector3(2.456752, 1.770302,-1.047782);
     sceneCam.transform.localPosition = Vector3(0.09087142, -0.4796396, 0.0500228);
     animation["Fall"].speed=1;
 
 
     {
         setOnFire.Play();
     }
 }
Comment
Add comment · Show 2
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 Baste · Dec 19, 2014 at 11:15 AM 0
Share

I formatted your code to show what it does better. And... what are you trying to do with the brackets around setOnFire.Play()?

avatar image IKilledKenny_2 · Dec 19, 2014 at 01:56 PM 0
Share

Oh Thank you!.Also,What im trying to do with setOnFire.Play is that i am trying to make an impact effect appear.For example.Pow! or Wham or Bop!

1 Reply

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

Answer by SkaredCreations · Dec 19, 2014 at 05:40 PM

Assign a default animation and change it accordingly to the Col.animation:

 function OnTriggerEnter (Col : Collider)
 {
     if (Col.tag == "Player")
     {
         // Default hit animation
         var anim : string = "Hit1";
         
         // Animation related to player's animation
         if (Col.animation.IsPlaying("Headbutt"))
             anim = "Fall";
         
         sceneCam.transform.position = Vector3(2.456752, 1.770302,-1.047782);
         sceneCam.transform.localPosition = Vector3(0.09087142, -0.4796396, 0.0500228);
         // animation[anim].speed=1; // Do you really need to set the speed?
         animation.Play(anim);
         
         setOnFire.Play();
     }
 }
Comment
Add comment · Show 4 · 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 IKilledKenny_2 · Dec 20, 2014 at 04:34 PM 0
Share

You $$anonymous$$ean This?

 #pragma strict
 
 var setOnFire : ParticleSystem;
 var player :Transform;
 var speed = 30;
 var pushPower = 2.0;
 var anim: String;
 
 
 function OnTriggerEnter (Col : Collider)
  {
      if (Col.tag == "Player")
      {
          // Default hit animation
          var anim : String = "Boeton_Fighting_Stance";
          
          // Animation related to player's animation
          if (Col.animation.IsPlaying("Triple_$$anonymous$$ick"))
              anim = "Hit1";
      
          animation.Play("Hit1");
          
          setOnFire.Play();
      }
  }

Because this isnt working

avatar image SkaredCreations · Dec 20, 2014 at 09:52 PM 0
Share

At line 21 you have to assign anim to Play, not "Hit1"

avatar image IKilledKenny_2 · Dec 21, 2014 at 04:30 AM 0
Share

OHHHHHH.......Ok now it works...Thank You So $$anonymous$$uch!

avatar image SkaredCreations · Dec 21, 2014 at 07:05 AM 0
Share

Accept the answer please, so the question will be moved from queue ;)

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

front check based on unity projects not working. 0 Answers

OnCollision Script... 2 Answers

Mesh and Sphere Collider Not Registering 2 Answers

Question on Static Primative vs Mesh Collider Performance 1 Answer

Why does the player jump is not so high if he touch 2 objects at the same time as if it touch only 1 object? 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