So Im creating a FPS game where you got an axe as a meele weapon and I managed to create an animation and everything works good just as I want except one thing
I would like to have 2 - 3 diffirent animations onto my axe and they play at random when Input(0) is clicked just like Half life when you are using your crowbar and smashing your leftclick on your mouse. so far I’ve only managed to create an array of the animationclips and I’ve looked at the random.range docs but I cant figure out how to do it. I have googled and checked other answers about arrays and random.range but no luck there.
Posting my code below
{
public Camera maincamera;
public float attackrange;
public int axedamage;
public int axeforce;
public AnimationClip[] animationer; //Array of animations
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
RaycastHit Hit;
Ray damage = maincamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
if (!animation.IsPlaying ("Axe_Hit") && !animation.IsPlaying("Axe_Unsheet"))
{
if(Input.GetMouseButtonUp(0))
{
//Random animations from the array playing here
Invoke("attack", 0.5f);
}
}
}
void attack()
{
RaycastHit Hit;
Ray damage = maincamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
if (Physics.Raycast (damage, out Hit, attackrange))
{
if(Hit.collider.tag == "Enemy")
{
Hit.collider.GetComponent<Enemy>().health -= axedamage;
}
if(Hit.rigidbody)
{
Hit.rigidbody.AddForce(damage.direction * axeforce);
}
}
}
}