So i’m having a problem with flipping my sprite, it works for one direction but not for the other. Maybe it’s just a stupid mistake but I just can’t find out what’s wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemyslimescript : MonoBehaviour
{
Rigidbody rb;
SpriteRenderer direction;
// Start is called before the first frame update
void Start()
{
rb = GetComponent <Rigidbody>();
direction = GetComponent <SpriteRenderer>();
}
// Update is called once per frame
void Update()
{
if (direction.flipX == true)
{
rb.velocity = new Vector3(-5, -1, 0);
}
if (direction.flipX == false)
{
rb.velocity = new Vector3(5, -1, 0);
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Obstacle")
{
if (direction.flipX == true)
{
direction.flipX = false;
}
if (direction.flipX == false)
{
direction.flipX = true;
}
}
}
}