0
\$\begingroup\$

I'm new to Unity. I'm trying to create a black screen transition when pressing a button using SetTrigger(). However it's not working. It doesn't even play at the start of the game. Can anyone help me?

Here is my code:

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown("x")) {
        Debug.Log("Hello");
        anim.SetTrigger("Crossfade");
} }

My settings:

enter image description here

enter image description here

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ provide animator controller ui too. i would like to see states and blend tree \$\endgroup\$
    – Anthony
    Commented Aug 2 at 4:24
  • \$\begingroup\$ And I assume the Debug.Log("Hello"); does appear in the console? \$\endgroup\$
    – Philipp
    Commented Aug 2 at 7:39
  • \$\begingroup\$ @Philipp yes it does \$\endgroup\$ Commented Aug 2 at 15:13

1 Answer 1

0
\$\begingroup\$

I don't think Animator.SetTrigger is very reliable, I've had same situations like this,

Debug.Log(1); 
Animator.SetTrigger();
Debug.Log(2);

And the result was that 1 and 2 were printed, but the SetTrigger function didn't work.

Using SetBool and setting the value back at the next frame instead might help.

--edit--

If even debug print hello doesn't appear, then it shouldn't have anything to do with the Animator, maybe you can should check the input function and try to use the

Input.GetKeyDown(KeyCode.X);

replace

Input.GetKeyDown("x");
\$\endgroup\$
1
  • \$\begingroup\$ I disagree with the claim that SetTrigger is inherently unreliable. The advice to change the input line also doesn't make sense given that we know the if is getting triggered correctly because the log prints. \$\endgroup\$
    – DMGregory
    Commented Aug 6 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .