Hello all, Hopefully this is the last time i need to be on here annoying people but i’ve hit upon one last snag. I had an icon for interactable objects that would show up when you hovered over them to let the player know that they could press on it.
using System.Collections;
using UnityEngine.UI;
public class Interact : MonoBehaviour
{
public string interactButton;
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 (isInteracting == false) {
if (interactIcon != null) {
interactIcon.enabled = true;
}
if (Input.GetButtonDown (interactButton)) {
if (hit.collider.CompareTag ("Door")) {
hit.collider.GetComponent<new_door> ().ChangeDoorState();
} else if (hit.collider.CompareTag ("Key")) {
hit.collider.GetComponent<New_key> ().Unlocknew_door ();
} if (hit.collider.CompareTag ("Fusebox")) {
hit.collider.GetComponent<Fusebox> ().FadeOut ();
}
}
else {
interactIcon.enabled = false;
}
}
}
}
}
It was this line that was added in at the end so i could interact with another object, before its inclusion the script worked perfectly. Now the icon only shows up when you press the interact button and i can’t for the life of me figure out why that is. If anyone could clarify this it would be greatly appreciated. and @Maniva This is honestly the last time I will bother you… at least for this game :L