I have a script for an animal that has the bool : isDead. I want my raycast to check if isDead is true or not. I have tried messing around with the syntax but I can’t figure it out. Thank you in advance!
using UnityEngine;
using System.Collections;
public class RayCast : MonoBehaviour {
Camera cameraMain;
float showWaterText;
public PlayerNeeds player;
void Start() {
cameraMain = GetComponent<Camera>();
}
void OnGui()
{
if (showWaterText == 1) {
print ("Water 2");
GUI.Box (new Rect ((Screen.width) / 2 - (Screen.width) / 8, (Screen.height) / 2 - (Screen.height) / 8, (Screen.width) / 4, (Screen.height) / 4), "Press E to drink.");
}
}
void Update() {
Ray ray = cameraMain.ViewportPointToRay (new Vector3 (0.5F, 0.5F, 0));
RaycastHit hit;
if (Physics.Raycast (ray, out hit, 3)) {
if (hit.transform.gameObject.tag == "Water") {
print ("Water");
showWaterText = 1;
if(Input.GetButton ("Use"))
{
player.playerThirst = 20;
}
}
else{
showWaterText = 0;
}
}
if (Physics.Raycast (ray, out hit))
{
if(hit.transform.gameObject.tag == "Animal")
{
if(hit.collider.gameObject.GetComponent<Animal>.isDead)
{
}
}
}
}
}
PS. The GUI box doesn’t show up when I look at the water. If you could also shed some light on that I would greatly appreciate it.