I made this script to basically change the ‘lookingAt’ variable when the player looks at an object, i have already tested this in another script and it worked before, but why wont it work in this one? all the public variables have been defined, and this script has been basically tweeked after copy and pasting it out of the working one, why wont it work now?
using UnityEngine;
using System.Collections;
public class RuneScript : MonoBehaviour {
public int LookingAt = 0;
RaycastHit Hit;
public GameObject mesh;
public GameObject topRune;
public GameObject leftRune;
public GameObject rightRune;
public LayerMask topRunestone;
public LayerMask leftRunestone;
public LayerMask rightRunestone;
public float Range;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 DirectionOfLine = mesh.transform.TransformDirection(Vector3.forward);
Debug.DrawRay (mesh.transform.position, DirectionOfLine * Range, Color.blue);
if (Physics.Raycast (mesh.transform.position, DirectionOfLine, Range, topRunestone.value)) {
LookingAt = 1;
}
if (Physics.Raycast (mesh.transform.position, DirectionOfLine, Range, leftRunestone.value)) {
LookingAt = 2;
}
if (Physics.Raycast (mesh.transform.position, DirectionOfLine, Range, rightRunestone.value)) {
LookingAt = 3;
}
}
void OnGUI () {
if (LookingAt == 0) {
GUI.Label (new Rect ((Screen.width/2)-75,10,150,50), "Not loo");
}
if (LookingAt == 1) {
GUI.Label (new Rect ((Screen.width/2)-75,10,150,50), "Click to activate Hagalaz");
}
if (LookingAt == 2) {
GUI.Label (new Rect ((Screen.width/2)-75,10,150,50), "Click to activate Nauthiz");
}
if (LookingAt == 3) {
GUI.Label (new Rect ((Screen.width/2)-75,10,150,50), "Click to activate Ansuz");
}
}
}