Trigger not playing animation

Hello everyone,

I’m currently experiencing a problem where the animation won’t play on trigger.

I am creating a platform where the first red trigger switch would enable and disable the first platform animation to move up and down. The second red switch has the same functionality just the animation moves left to right.

I created a platform script on the Platform_1 and 2 under PlatformParents. I exposed 3 fields, the animator, the platform as a reference, and switch because it needs to trigger.

Here’s my code, I am missing anim.Play(); but I don’t know what to call since its only one script:

public class PlatformScript1 : MonoBehaviour
{
    [SerializeField] Animator anim;
    [SerializeField] GameObject Platform;
    [SerializeField] GameObject Switch;

    // Use this for initialization
    void Start()
    {
        anim = GetComponent<Animator>();
    }

    void OnTriggerEnter2D(Collider2D collision)
    {
        if (gameObject.tag == "Player")
        {
            Debug.Log("Played");

            //anim.enabled = true;
            anim.SetBool("Play", true);
            anim.Play("platform_1");
            anim.Play("platform_2");  //Needs to wait for 5 seconds, use coroutine?
        }
        else
            anim.SetBool("Play", false);       
    }
}

My Switch script is under the SwitchTrigger parent also has exposed fields for animation and platform for it to link:

public class SwitchScript : MonoBehaviour {

    [SerializeField] Animator anim;
    [SerializeField] GameObject platform;

    void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.tag == "Player" )
        {
        Debug.Log("touched");
        anim.SetBool("platform_1",true);
        anim.SetBool("platform_2", true); 
        }
    }
}

The Play parameter is set in the animation state that I created

Thanks for the help everybody.

Line 15,

if (gameObject.tag == "Player")

should be

if (collision.gameObject.tag == "Player")

You are checking if the Platform itself has the Player tag.