Trying to Make an Interact Icon Appear
Hello all, I'm kind of new to unity and C++. I'm trying to make an Interact Icon appear when the player is near an interactive object. Basically a note. I watched some tutorials and used this code. I set the tag for the note as "Note" and its layer as "Interactable" so that I can put it in the script box. I added the Icon to the script and the scene and also the note has a box collider.
The script itself doesn't give any errors however when the player comes near the note there is nothing happening as well.
Is there anyone to help me please, I'm stuck.
Thanks in advance,
public float interactDistance = 3f;
public LayerMask interactLayer;
public Image interactIcon;
public bool isInteracting;
void Start()
{
if(interactIcon !=null) {
interactIcon.enabled = false;
}
}
void Update()
{
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, interactDistance, interactLayer))
{
if (interactIcon != null)
{
interactIcon.enabled = true;
if (Input.GetKeyDown(KeyCode.E))
{
if (hit.collider.CompareTag("Note"))
{
hit.collider.GetComponent<Note>().ShowNoteImage();
}
}
}
}
else
{
interactIcon.enabled = false;
}
}
}
Answer by Xanaxer · Mar 12, 2019 at 06:41 PM
For anyone experiencing the same thing, I have found the solution; I changed public LayerMaskt to an int now it works like a charm
Your answer
Follow this Question
Related Questions
ui Text not responding to collider 1 Answer
why isnt my code working, 2 Answers
ANIMATION TRIGGER DOESN'T PLAY 1 Answer
Ignore collision based on position 1 Answer
How to make an object that collides with just the player? 1 Answer