- Home /
Animation Starts on begin play
Hi, I have this really annoying problem and I am far too much of a beginner to unity to know how to fix it. I have an animation clip that I only want to play if a certain 'If' statement is fulfilled. But at the moment it just plays on repeat whenever I begin play.
public class BloodScreenScript : MonoBehaviour
{
public GameObject DeathArea;
Animator blanim;
public void OnTriggerStay(Collider collider)
{
if (DeathArea.GetComponent<EnterDarknessScript>().counterdeath >= 7)
{
blanim = GetComponent<Animator>();
blanim.SetTrigger("ShowText");
}
}
}
I have set up an animator composition for this as well. It goes from Entry to New State to My Animation. I have made a Parameter which is 'ShowText' (also featured in the script) and the conditions for the connection between the New State and My Animation is set to that Condition.
I just have no idea what is wrong so any help would be muchly appreciated.
Answer by brewster2110 · Apr 14, 2018 at 01:28 AM
I fixed it. I ended up having to set up a whole new Animation Trigger and just messing with the get component setting in my scripts. Thanks for the help!
Answer by ThePixelatedSword · Apr 13, 2018 at 10:58 PM
The reason this is happening is because the animation controller needs a default animation to go to. If that is the only animation you have in the controller, it will play. The best way the solve this is to create another animation in which nothing happens. Then set it as the default animation by right clicking on it and selecting "Set as layer default state". It will then become orange. You then must make a transition between them by right clicking the new animation and selecting "Make Transition" and then clicking on the old one. Click on the transition and make sure "Has Exit Time" is false.
I tried to do this as you said, but was a little unclear on what you meant by creating a new animation. I added a new state and gave it an animation where nothing happened. Didn't work though. Not sure if i''m doing it right. I attached an image Thanks
I'm sorry for being unclear. Did you make sure "Has Exit Time". That's the only thing I can think of that would stop the animation from playing unless you did set up your parameters in the controller.
The transition which is highlighted in blue is the one that I unchecked "Has Time Exit". Whenever I start the game it still shows up straight away still and doesn't wait for it to be called upon. Thanks though
Your answer
Follow this Question
Related Questions
Why when creating new animator controller for the character the character is not walking right ? 0 Answers
Strange animation behaviour trying to implement hover functionality 1 Answer
2D animation diferent right and left 0 Answers
Animator Trigger Not Working 1 Answer
Has Exit Time causes between trigger and transition. How can I stop this? 1 Answer