- Home /
I am trying to make a gun recoil with an animation and in this script it only runs after the first mouse click. This is probably an easy fix I just can't seem to wrap my head around it. This is my script.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class shootanim : MonoBehaviour {
public Animator anim;
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if(Input.GetButton("Fire1")){
anim.Play("shoot");
}
else if(Input.GetButtonUp("Fire1")){
anim.enabled = false;
}
}
}
Answer by imM4TT · Jul 17, 2018 at 03:23 AM
Hi
To make your code work, I think that you only need to write anim.Stop("shoot");
at line 13 instead of anim.enabled = false;
But there is a difference between animation & animator and it's not the appropriate way to use the animator component
It's more useful to create an animator if the character have several animations which can bridge between them
I advise you to create an animator for your character ( simple and efficient )
You can look there : https://www.youtube.com/watch?v=JeZkctmoBPw
In the other case, you can use the animation component which work like you did above.
Your answer
Follow this Question
Related Questions
Scripting: make thing repeating 3 Answers
Mirrored animation doesnt rotate correctly 0 Answers
Animation from Blender 0 Answers
Any idea why my animation isn't working? 0 Answers
Can't change transform rotation of GO with an animation that change it's rotation 3 Answers