- Home /
How do you change a layer weight within a script?
I'm new to unity and programming in general and I'm trying to write a script that sets an animation layer weight to 0 when the left mouse button is pressed down, and when the mouse button is released, reset the animation layer weight back to 1. So far I've had no luck and could really use some help.
Answer by UTus · Sep 25, 2020 at 02:39 AM
I appreciate the fast reply! however I've been trying that (I realize i should have included this in my question) but I've been trying to use the following in my script.
public float animationLayer; public Animator anim;
void Update () { if (Input.Get$$anonymous$$ouseButtonDown(0)) { anim.SetLayerWeight(0, animationLayer); }
if (Input.Get$$anonymous$$ouseButtonUp(0))
{
anim.SetLayerWeight(1, animationLayer);
}
}
but it will only sometimes change one time and, when it does sometimes change it does the opposite of what i want it to do for some reason. Am I typing something in wrong or forgetting something at all? Again thank you for the fast reply.
Your answer
Follow this Question
Related Questions
How to run my jump animation in unity3d? 0 Answers
Need script to do something when animation finished ? 1 Answer
Gameobject animation when loaded with Resource.load 0 Answers
Play either the first or second animation on an object without specifying its name 1 Answer
Animation layer naming convention between enemies and player 0 Answers