Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Codelyy · May 29, 2016 at 02:29 AM · animatoraiif-statementsreturn

Secound Animator.GetCurrentAnimatorStateInfo(0).IsName() doesn't work in if Statement

I've been trying to figure out why this problem is happening for a while now but I just can't.

Basically I've set up a laser beam script with a if statement saying that if a certain animation isn't playing then don't fire the laser beam. This is of course so the laser beam fires on the correct animation. I've done it like this:

 if(!anim.GetCurrentAnimatorStateInfo(0).IsName("LaserBeam") && !laserBeaming)
         {
             transform.position = new Vector3(transform.position.x + 3.5f * Time.deltaTime, transform.position.y, transform.position.z);
             return;
         }

With the laser beam script below it.

I recently added a angry mode for the enemy I'm using this script on and I want the enemy to do the same attacks but at different speeds. I have different animations for when the enemy is angry though with one of the animations being "Angry-LaserBeam" which is basically the same animation as "LaserBeam". I only want the laser beam to fire when the enemy is angry if the "Angry-LaserBeam" animation is playing.

This is the if statement now:

 if(!anim.GetCurrentAnimatorStateInfo(0).IsName("LaserBeam") && !laserBeaming || !anim.GetCurrentAnimatorStateInfo(0).IsName("Angry-LaserBeam") && !LaserBeam)
         {
             transform.position = new Vector3(transform.position.x + 3.5f * Time.deltaTime, transform.position.y, transform.position.z);
             return;
         }

The problem I am having is if i have that line: "!anim.GetCurrentAnimatorStateInfo(0).IsName("Angry-LaserBeam")" in the if statement then it will never run the code below it, even if the animation "Angry-LaserBeam" is playing. Neither will the laser beam script run even if the animation is just "LaserBeam" when the enemy isn't angry if that line is in the if statement.

I just can't figure out why it's doing this and it has to be that line as if i remove it, the laser beam script works. It also works if I just have "!anim.GetCurrentAnimatorStateInfo(0).IsName("Angry-LaserBeam")" instead of "!anim.GetCurrentAnimatorStateInfo(0).IsName("LaserBeam")" so I've most likely done the "or - ||" part wrong.

Does anyone know what's going on?

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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Animator/Behaviour I want to get all the transitions of a state 0 Answers

Help implement such attacks 1 Answer

Using bool function with parameters 1 Answer

What if-statement to choose and how to involve. 2D 0 Answers

ARCore vertices Coordinates in unity 0 Answers


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