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 Robby-rEINEWALD · Oct 30, 2014 at 02:24 PM · animationcolliderbooleandamage

Boolean doesn't change as I want

I have put boolean like this

 function OnTriggerEnter(other : Collider){
     if(other.tag == "shot"){
         move = false;
         hurt = true;
         health--;
         Destroy(other);
     }
 }

but it never change as I type in function update

 function Update(){
     if(move && health > 0 && !hurt){
         GetComponent(NavMeshAgent).destination = target.position;
         animation.Play("walk01");
     }
     if(hurt && health > 0){
         animation.Play("damage01");
         hurt = false;
     }
     playerDistance = Vector3.Distance(player.transform.position, transform.position);
     if(playerDistance <= 1){
         if(!attacking && health > 0 && ! hurt){
             move = false;
             this.GetComponent(NavMeshAgent).Stop();
             animation.Play("attack01");
             Invoke("ApplyDamage", 1);
             attacking = true;
         }
     }
     if(playerDistance > 1 && playerDistance <= 10 && !attacking && health > 0 && !hurt){
         move = true;
         animation.Play("walk01");
     }
     if(playerDistance > 10 && health > 0){
         move = false;
         GetComponent(NavMeshAgent).Stop();
         animation.Play("idle");
     }
     if(health <= 0){
         die();
     }
 }

I want hurt become true so the animation damage can run.

Comment
Add comment · Show 3
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 Unitraxx · Oct 30, 2014 at 02:26 PM 1
Share

Have you tried putting Debug.Log statements? Is the code inside the if statement in the OnTriggerEnter ever executed?

avatar image Mayank Ghanshala · Oct 30, 2014 at 02:27 PM 0
Share

where did you set hurt = true?

avatar image Robby-rEINEWALD · Oct 31, 2014 at 02:12 AM 0
Share

no, but the OnTriggerEnter can reduce health succesfully, so I think I can set boolean.

3 Replies

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

Answer by N1warhead · Oct 31, 2014 at 03:14 AM

I'm used to C#, but I'll try to point out what MAY be wrong.

Change this

      function OnTriggerEnter(other : Collider){
     if(other.tag == "shot"){
     move = false;
     hurt = true;
     health--;
     Destroy(other);
     }
     }

to this

      function OnTriggerEnter(other : Collider){
     if(other.gameObject.tag == "shot"){
     move = false;
     hurt = true;
     health--;
     Destroy(other);
     }
     }


Then the last part, I'd suggest restructuring your code so certain things are called before others. I've had that problem before with a bool where one was being called before the other just out of co-incidence.

Hope that helps!

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 Robby-rEINEWALD · Oct 31, 2014 at 04:17 AM 0
Share

I have fixed it

 if(hurt){
         if(health > 0){
             move = false;
             animation.Play("damage01");
         }
         hurt = false;
     }



Animation can run when I don't use hurt = false. But I need to set it become false, so it will not loop.

avatar image
0

Answer by smoggach · Oct 30, 2014 at 02:25 PM

You will not get the OnTriggerEnter callback unless one or more of the objects have a rigidbody. I'm guessing neither of your objects has one.

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 Robby-rEINEWALD · Oct 31, 2014 at 02:15 AM 0
Share

each of my object and my bullet have rigidbody.

avatar image
0

Answer by Unitraxx · Oct 30, 2014 at 02:34 PM

This is a duplicate question. You've asked exactly the same in http://answers.unity3d.com/questions/819747/how-can-i-play-damage-animation-after-colliding.html. Can someone please close this (or the other one)?

EDIT: Since you have 4 questions regarding the same piece of code, I suggest using the edit button to update your question instead of making new questions.

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 Robby-rEINEWALD · Oct 31, 2014 at 02:10 AM 0
Share

Thank you for your suggest, but I'm affraid they will say out of topic.

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

6 People are following this question.

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

Related Questions

Damage Animation doesn't play 1 Answer

Animation not being played! 0 Answers

My animation keeps on repeating on my animator 1 Answer

Hi, Im trying to make a sword swing animation, but it is playing non stop how can I make it go back to Idle Animation? 4 Answers

Collider on Bone changes Bone Origin/Pivot 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