Hi !
I’m trying to launch the animation of my creature when I click on a button.
In the script I created a void stop for my button but it doesn’t work… In my console the word “coucou” appears but it doesn’t play the animation and I don’t know what is wrong ![]()
using UnityEngine;
using System.Collections;
public class attackCreature : MonoBehaviour
{
Animation anim;
public void stop()
{
Debug.Log("coucou");
anim["creature1Attack1"].wrapMode = WrapMode.Once;
anim.Play("creature1Attack1");
}
void Start()
{
anim = GetComponent<Animation>();
anim.Play("creature1Idle");
}
void Update()
{
var goblin = GameObject.Find("GOBLIN");
var creature = GameObject.Find("creature1");
var distance = Vector3.Distance(goblin.transform.position, creature.transform.position);
//Debug.Log(distance);
if (distance < 2)
{
anim.Play("creature1walkright");
}
if (anim.IsPlaying("creature1Attack1"))
{
anim.Play("creature1Idle");
}
if (distance >= 2)
{
anim.Play("creature1Idle");
}
}
}