Answer the question
In order to leave comments, you need to log in
The object ignores objects with a specific tag. What is the reason and how to fix it?
I have a script (trigger) that should turn the player to an object with a specific tag, but it ignores the objects. It works with other objects with the tag. Why and how to fix it?
Trigger script:
using UnityEngine;
public class Player : MonoBehaviour
{
public Transform npc;
public Transform player;
public string Tag;
private void Update()
{
transform.position = player.position;
transform.rotation = player.rotation;
}
public void OnTriggerStay2D(Collider2D collision)
{
if (collision.transform.gameObject.CompareTag(Tag))
{
npc = collision.transform;
Quaternion lookRotation = Quaternion.LookRotation(Vector3.forward, npc.position - player.position);
player.rotation = Quaternion.Euler(0, 0, lookRotation.eulerAngles.z + 180);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question