If I go near the object that this script is attached to and press ‘e’, nothing happens. I do have a MonoBehaviour
and object assigned in the inspector.
var script : MonoBehaviour;
var object : GameObject;
private var arrayIndex = 0;
private var arr : MonoBehaviour[];
function Awake() {
if (script == null)print ("Script value is not assigned, you will get a NullRefExc if you continue");
arr = GameObject.FindObjectsOfType(script.GetType()) as MonoBehaviour[];
if (arr == null || arr.Length == 0)
print ("No objects of type " + script.GetType() + " was found");
}
function Update() {
if(Vector3.Distance(object.transform.localPosition, this.transform.localPosition) < 2) {
if(Input.GetKeyDown(KeyCode.E)) {
if (script.GetType() == typeof TransformObject) {
var obj = script as TransformObject;
obj.condition = true;
Debug.Log("Button pressed. ");
}
}
}
}