- Home /
Question by
kenwiggins93 · Jun 22, 2020 at 10:35 AM ·
animationscripting problemanimatorloop
Animator trigger keeps retriggering.
So my animation trigger seems to be retriggering constantly giving a looping effect where I just want it to play once with the button click. (I've deactivated the loop option on the animation.)
The animator has the trigger condition leading from anystate to 'Eat', and then I've experimented with exit times, no exit times etc. I think it's a scripting issue making a loop somewhere, but I can't figure it out. Any ideas?
Code looks like this
public class Food : MonoBehaviour
{
public int foodValue;
public int happyValue;
public int energyValue;
public Button foodButton;
public GameObject poop;
public static bool isOttoEating;
public GameObject otto;
Animator anim;
// Start is called before the first frame update
void Start()
{
// anim = otto.GetComponent<Animator>();
foodButton.onClick.AddListener(TaskOnClick);
if (otto.GetComponent<Animator>() != null)
{
//NADA
}
else
{
anim = otto.GetComponent<Animator>();
}
isOttoEating = false;
}
void TaskOnClick()
{
if (Otto_Data.isOttoSleep == true)
{
}
if (Medicine_Script.isOttoSick == true)
{
}
else
{
Otto_Data._hungerA += foodValue;
Otto_Data._happiness += happyValue;
Otto_Data.energy += energyValue;
isOttoEating = true;
if (Otto_Data._hungerA >= 100)
{
anim.SetTrigger("Dissmiss"); //this also doesn't seem to work even though it did at one point :/
}
if (Otto_Data._hungerA <=99)
{
anim.SetTrigger("Eat"); //This is what I want to trigger, it does trigger with the button click, but then seems to retrigger constantly...
anim.SetTrigger("Active");
}
}
}
private void Update()
{
anim.ResetTrigger("Eat"); // I introfuced this to try and solve the problem, but its inclusion/exclusion seems to have no effect.
if (Otto_Data.energy <= 0)
{
foodButton.interactable = false;
}
else
{
foodButton.interactable = true;
}
if (Otto_Data._hungerA >= 100)
{
// foodButton.interactable = false;
}
else
{
foodButton.interactable = true;
}
if (Otto_Data.energy <= 2000 && Otto_Data.isOttoSleep == true)
{
foodButton.interactable = false;
}
if (Medicine_Script.isOttoSick == true)
{
foodButton.interactable = false;
}
//if (Otto_Data._hungerA == 50)
{
// GameObject newPoop = Instantiate(poop);
// Destroy(newPoop, 60);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Character Animator controller/movement 1 Answer
Is there a new retargetting system for the animation in 5.5? 1 Answer
How to stop animation from playing in c#. 7 Answers
Changing speed of specific animation state, at runtime 1 Answer
Is there a way to turn off an animation looping in a script? 0 Answers