- Home /
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);
}
}
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
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();
}
}
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!
Your answer
![](https://koobas.hobune.stream/wayback/20220613141504im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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