I’ve tested around a little and I’ve pinpointed that the problem may be in the if(other.gameObject.CompareTag(“Enemy”)) line, but it may be in somewhere else in the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if (Input.touchCount > 0)
{
//moving the player
Touch touch = Input.GetTouch(0);
Vector3 touchPos = Camera.main.ScreenToWorldPoint(touch.position);
touchPos.z = 0f;
touchPos.x = -7f;
transform.position = touchPos;
}
}
//destroying player + logging it when the enemy touches the player
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.CompareTag("Enemy"))
{
Destroy(gameObject);
Debug.Log("Death");
}
}
}