- Home /
How to make left clicking start an animation?
I'm trying to make it so that when I left click my shield will come out to block. I have the animation, now I need to know how to call in the animation from the script (.cs) I would not recommend Unity for just starting in coding, haha. I just need to know how to do it. So yeah, also if you can help me out by adding what it does // or */ whatever it is in .cs that is used to define, that'd be great since I don't just want answers, I want to learn.
Answer by $$anonymous$$ · Jul 15, 2014 at 10:19 PM
function Input.GetMouseButtonDown(0)) } play.Animation("AnimationName"); }
Worked for me. (Or something similar, mess around with it if it doesn't, I'm doing this off memory.
@$$anonymous$$ - your memory is a bit mixed up. To work, your code would be:
if (Input.Get$$anonymous$$ouseButtonDown(0)) {
animation.Play("AnimationName");
}
Also, you seem to be answering your own old question?
@robertbu $$anonymous$$y bad. And I decided I should leave the answer so that people looking for an answer on here don't have to search through the whole document @Fornoreason1000 provided. Even though I am grateful and it taught me some things, I find it'd be easier for everyone else.
Answer by Fornoreason1000 · Jun 07, 2014 at 09:21 AM
Ok.... For coding practice you should try unity Gems or even just you tube Google C# tutorials often gives good results.
Do you know if your using Legacy or Mecanim Animations? the method t control them in C# is different for the two types. its more or less the same... but basically you use a state machine to check and set which animation state you are in... then make an condition that stipulates whenever you press the left moue button.. you set your Animation state to the state and your animation will play Mecanim tutorials http://docs.unity3d.com/Manual/MecanimAnimationSystem.html http://docs.unity3d.com/ScriptReference/Animator.html www.youtube.com/watch?v=Xx21y9eJq1U
Legacy http://docs.unity3d.com/420/Documentation/Manual/Animations40.html http://docs.unity3d.com/ScriptReference/Animation.html C# tutorials
http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx www.youtube.com/watch?v=SXmVym6L8dw www.burgzergarcade.com/
Your answer
Follow this Question
Related Questions
How to play sprites animation on the place that we click? 0 Answers
2D: How to Move On Click with Creatable (On Click) Waypoints 1 Answer
How To Play Animation On UI Button Click Please... Im Going To Freak Out Please Enter And Help Me 2 Answers
Object reference not set to an instance of an object 1 Answer
How to call an Animation? 1 Answer