• 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 question was closed Jun 11, 2013 at 07:08 AM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Griffo · Jun 10, 2013 at 07:36 PM · variablemecanim

Can this be done ?

Hi, I think Mecanim has a big minus, what I do in script is make a variable called attackDistance then set it in the inspector depending on the type of enemy, and some times after testing I decide to change it, so I set up Mecanim and all works fine untill I decide to change the variable attackDistance in the inspector the I have to go into Mecanim and change the value in the picture below to match the variable attackDistance, wouldn't it be a lot easier if I could assign a variable there that I could link to the variable attackDistance in script, am I missing something, is there another way, or can it not be done ?

alt text

grab-01.jpg (43.1 kB)
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

  • Sort: 
avatar image
0
Best Answer

Answer by TonyLi · Jun 10, 2013 at 08:02 PM

You could always use only the Mecanim value by using Animator.Get/SetFloat() (or Integer if that's what you're using) in your script.

Maybe, instead, you could use a Mecanim parameter to keep track of state rather than distance. Perhaps an integer attackStyle instead of attackDistance, where attackStyle==0 might trigger a wrestling move, attackStyle==1 a punching move, attackStyle==2 a kicking move, and attackStyle==3 a ranged-distance move.

Then, in your script, when the character moves to whatever you define as punching range (perhaps a script variable value attackDistance around 10), you could call Animator.SetInteger("attackStyle", 1). This way, Mecanim doesn't need to know what distance thresholds you're currently using. It only knows that it's time to do a punch.

In practice, the integers should really be constants or enums (e.g., enum AttackStyle { Grapple=0, Punch=1, etc. }).

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 Griffo · Jun 11, 2013 at 06:38 AM 0
Share

TonyLi, again thanks for the input, I decided to go with a boolean, Running, Walking, if true run, walk, and setting it in the script depending on the distance.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Animation Speed with Variable? 1 Answer

Problem using mecanim and the Animation process 0 Answers

y value doesn't update 1 Answer

Public Variables in MonoBehaviour Scripts reset to "None" in Playmode 0 Answers

Reading reference variable alters said reference variable 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