I am trying to get an image to display when the player is looking at the object of which the script is attached, and in contact with its box collider trigger. The image is a component of the object named “interactImage” and I intend on displaying it to the user by disabling/enabling it’s “canvas” component. You can see the script below:
using UnityEngine;
using System.Collections;
public class interactText : MonoBehaviour
{
bool isLook;
bool isCollide;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (isCollide == true && isLook == true)
{
GameObject.Find("interactImage").GetComponent<Canvas>().enabled = true;
}
}
void OnTriggerEnter(Collider collide)
{
isCollide = true;
}
void OnTriggerExit(Collider collide)
{
isCollide = false;
GameObject.Find("interactImage").GetComponent<Canvas>().enabled = false;
}
void OnBecameVisible()
{
isLook = true;
}
void OnBecameInvisible()
{
isLook = false;
GameObject.Find("interactImage").GetComponent<Canvas>().enabled = false;
}
}
This script, simply put, does not display. When the player triggers and looks at the object, the image does not display in the camera’s view. I don’t know why. Any thoughts?