- Home /
Question by
p90xtr3m3 · Jan 12, 2015 at 04:47 PM ·
c#animationparameters
How to get an animation to play when clicked.
I am very new to scripting, and i need help, i am not sure what is wrong with my code, here it is:
using UnityEngine;
using System.Collections;
public class punchC : MonoBehaviour {
// Use this for initialization
Animator anim;
void Start () {
anim = GetComponent<Animator> ();
Animator.StringToHash("leftPunch");
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {
anim.SetBool ("leftPunch", true);
} else {
}
}
}
Comment
Check if in the animator component, you actually set a transition (the arrow) between your 2 animations (for example idle to leftpunch) and set the transition parameter to be a boolean (leftpunch). Also remove the else{}, it is empty anyways. Good luck! (btw the Unity $$anonymous$$ecanim tutorial is pretty good)
Would this work?
if (Input.Get$$anonymous$$ouseButtonDown (0))
{
//tell selected character to "leftPunch"
GetComponent<Animation>().Crossfade("leftPunch");
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Why aren't my parameters for animation not working? 0 Answers
Distribute terrain in zones 3 Answers
changing animations on an object without the script. 0 Answers