I made a script with some help online. It is supposed to check if the player hasn’t collided with a enemy and enable to move on the x axis. The movemet is fine but the colliding part is not working and is really confusing,
So i have 2 sprites. The player and the slime. What i want it to do is when the player and the slime collide it disables the movement. Both have rigidbody 2D and box collider and the player has the script. Right now the player just pushes the slime but i want the slime to stay still / move itself.
using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour
{
public float speed = 1.5f;
public bool alive = true;
void OnCollisionEnter(Collider2D other)
{
if (other.gameObject.tag == "Slime")
alive = false;
}
void Update()
{
if (alive = true)
{
if (Input.GetKey(KeyCode.A))
{
transform.position += Vector3.left * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D))
{
transform.position += Vector3.right * speed * Time.deltaTime;
}
}
}
}