- Home /
Mechanim issues
I've created a bow with full animations and I'd like to assign them using mechanim. My code has been having alot of issues and I don't know that I'm on the right track. Any clues? Thanks.
using UnityEngine;
using System.Collections;
public class mechanim : MonoBehaviour {
Animator anim;
static bool idleState = Animator.StringToHash("Base Layer.Idle");
static bool reloadState = Animator.StringToHash("Base Layer.reload");
static bool pullHoldState = Animator.StringToHash("Base Layer.pullHold");
static bool waitFireState = Animator.StringToHash("Base Layer.waitFire");
static bool fireState = Animator.StringToHash("Base Layer.fire");
static bool failAttemptState = Animator.StringToHash("Base Layer.failAttempt");
void Start ()
{
anim = GetComponent<Animator>();
}
void Update ()
{
AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);
/*float move = Input.GetAxis ("Vertical");
anim.SetFloat("Speed", move);
if(Input.GetKeyDown(KeyCode.Space) && stateInfo.nameHash == runStateHash)
{
anim.SetTrigger (jumpHash);*/
}
void FixedUpdate ()
{
if(Input.GetButtonDown("Fire1"))
{
anim.SetBool(reloadState, true);
//then pullHold
//then waitFire
}
if (Input.GetButtonUp ("Fire1") && (waitFireState == true))
{
anim.SetBool (fireState, true);
}
else if (Input.GetButtonUp ("Fire1") && (waitFireState == false))
{
anim.SetBool (failAttemptState, true);
}
}
What issues are you having with it? my first thought would be moving your input handling into Update() ins$$anonymous$$d of FixedUpdate() as according to this: https://docs.unity3d.com/Documentation/ScriptReference/Input.html
I tried moving them to update, the errors remain, here they are:
Assets/Scripts/mechanim.cs(12,49): error CS0029: Cannot implicitly convert type int' to
bool'
Assets/Scripts/mechanim.cs(27,30): error CS1502: The best overloaded method match for UnityEngine.Animator.SetBool(string, bool)' has some invalid arguments Assets/Scripts/mechanim.cs(27,30): error CS1503: Argument
#1' cannot convert bool' expression to type
string'
Answer by tanoshimi · May 10, 2014 at 06:29 AM
Animator.StringToHash returns an int - you're trying to assign it to bool variables (idleState, reloadState etc.)