Hello everyone, I’m new here, and i just began a 2D platform game. In the end, the player has to defeat the lion, which goes towards the player. When the player goes from one side of the lion to its other, the lion is supposed to look on the other side, and I don’t know why, it doesn’t work. In this case, I used an animator bool, and a box collider above the lion. When the player goes trough it one time, the bool is supposed to change to “true”, and when the player does it again, it is supposed to get false again. All this linked to the two animations of the lion, one facing right, the other one facing left.

And here’s the code of the “wall” which stands above the lion (I’m french so please excuse me if I made some spelling mistakes; Here “vraifaux” stands for “truefalse”):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallToFlip : MonoBehaviour {
public Animator lionanimation;
public bool vraifaux;
// Use this for initialization
void Start () {
lionanimation = GameObject.FindGameObjectWithTag ("lion").GetComponent<Animator> ();
vraifaux = false;
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
vraifaux = !vraifaux;
}
}
void Update(){
lionanimation.SetBool ("facingRight", vraifaux);
}
}
And here is the code of the lion:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LionAI : MonoBehaviour {
public float speed = 0.5f;
public Transform player;
// Use this for initialization
void Start () {
player = GameObject.FindGameObjectWithTag ("Player").transform;
}
// Update is called once per frame
void Update () {
Vector3 displacement = player.position -transform.position;
displacement = displacement.normalized;
if (Vector2.Distance (player.position, transform.position) > 1.0f) {
transform.position += (displacement * speed * Time.deltaTime);
}
}
}
Thanks for your understanding, and I wish to all of you a pleasant day.
v1ruso