Hey everyone,
this is my first attempt at coding my own game and i am a serious beginner!
anyway i have set up a player and an npc character within my world and i am trying to make them interact with each other. ive set up a box collider with a trigger for my npc character and this is the code i am attempting to use for it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NPCScript : MonoBehaviour {
void OnTriggerEnter2D(Collider2D col )
{
if (col.CompareTag(“Player”))
{
Debug.Log(“Player Entered Interaction Zone”);
}
}
void OnTriggerStay2D(Collider2D col)
{
if (col.CompareTag(“Player”))
{
if (Input.GetKeyDown(“e”))
{
Debug.Log(“Player Interacted With NPC”);
}
}
}
}
however it only debugs the message to the console when i have the player physically moving inside of the collider and also it is logging the “Player Interacted With NPC” message twice.
is there something i am doing wrong?
thanks,
Charlie.