Starting a 2D animation on a trigger

Making a game where you play as a character made of fire. I want to make it so when the player jumps into the torch, the torch lights and the fire animation appears and plays. Here is what I have coded so far, I just can’t figure out how to only start playing the animation once torchIsLit = true

public class lightTorch : MonoBehaviour {

	private bool torchIsLit = false;

	Animator anim;

	// Use this for initialization
	void Start () {
		anim = GetComponent<Animator> ();
	}
	
	// Update is called once per frame
	void Update () {

		if (torchIsLit) {
			Debug.Log ("Torch Lit");
		}
	}

	void OnTriggerEnter2D(Collider2D other) {
		torchIsLit = true;
	}

}

Why don’t you simply play the animation inside the OnTriggerEnter2D ?

Depending on the animator (state machine) you have created, you may want to play the animation using a trigger.

In your animator :

[`<newEmptyState>`] ---→ [`<nameOfYourAnimation>`]

with the transition triggered by a trigger parameter.

Then, you call anim.SetTrigger(<nameOfYourTrigger>);