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 billybillyjim · Mar 29, 2014 at 06:59 PM · animationjavascriptparameters

Unity Animation Parameter Not Changing

Hi, I'm relatively new to Unity and I am completely stumped by this. I currently just have two states, GuyOne and GuyTwo. They have a transition between them, so that if the parameter is equal to 2, it should switch. If i use my code and have it switch to 2 in the update function, the animation immediately switches to GuyTwo, which tells me that it works. However, if I try to make the animation switch to an integer variable instead of 2, the animation never switches, even if I click a GUI button that switches the variable to 2. The Debug.Log always outputs 2 when I click the button, but the parameter never changes, no matter what I try.

I'm hoping to make it work so that the parameter changes on the button click and it doesn't have to check for it in the Update function, but right now I'd be happy with anything. Any help is greatly appreciated, thanks!

 var mashers : float = 1;
 var mashMultiplier : float = 1;
 var masherUpgradeCost : float = 1;
 var bodyLevel : int = 1;
 var anim : Animator;
 
 
 function Start () {
 
     anim = GetComponent(Animator);
 
 }
 
 function Update () {
 
     anim.SetInteger("currentBodLev", bodyLevel);
 
 }
 
 function upgradeMasher(){
     if(mashers > masherUpgradeCost){
     
         mashers = mashers - masherUpgradeCost;
         mashMultiplier = mashMultiplier * 1.5;
         masherUpgradeCost = masherUpgradeCost * 2;
         bodyLevel++;    

         Debug.Log(bodyLevel);
         
     }
 }
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 getyour411 · Mar 29, 2014 at 07:09 PM 0
Share

It's not clear to me what the difference is between "2" and "an integer value". Perhaps your OnGUI code for the button click is the culprit, please show the relevant part

avatar image billybillyjim · Mar 29, 2014 at 07:32 PM 0
Share

I'm unsure of what the difference is either. If I tell the program

 anim.SetInteger("currentBodLev", 2);

it works, as long as it is in the update function. But if I say

 anim.SetInteger("currentBodLev", bodyLevel);

and bodyLevel equals 2, it does not work, even in the update function.

The code for the OnGUI is this(The name of the other script is Button$$anonymous$$ashing):

  import System;
     
     var styleOne : GUIStyle;
     
     var scriptName : GameObject;
     
     
     function OnGUI(){
     
     if(GUI.Button(Rect(Screen.width - 100, 150, 90, 50), "UPGRADE \n $$anonymous$$ASHER")){
     
          scriptName.GetComponent(Button$$anonymous$$ashing).upgrade$$anonymous$$asher();
          
     }
     }
 

1 Reply

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

Answer by billybillyjim · Mar 29, 2014 at 09:54 PM

I figured it out! I somehow had two of the same script component on the same object. It must have messed something up. It's working now!

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

20 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

Related Questions

Animation doesn't work 1 Answer

Using animations in prefabs 1 Answer

Animation will not Return to Proper State 2 Answers

how to manage fbx files animation (blender) in unity using favascript 0 Answers

How do I animate a 2D sprite? 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