OnGui in not working if I have the Hover function updated in Update. The print shows that showLabel is changing from false to true as I hover over the object but the label will not come up. Here are the two scripts that are talking to each-other:
Interactee.js
var Interactable : boolean = true;
private var showLabel : boolean;
function Update(){
print (showLabel);
Hovers(false);
}
//Is the player interacting with the this object???
function Interact(Interacting : boolean){
if (Interactable){
if (Interacting){
//Action();
}
}
}
function Hovers (Hovering : boolean){
if(Hovering){
showLabel = true;
}else{
showLabel = false;
}
}
//The Action you want to happen...
/*function Action(){
//Make the item a child of backpack...
this.transform.parent = backpack.transform;
}*/
//While hovered show something...
function OnGUI(){
if (showLabel){
GUI.Label (Rect (Screen.width*0.5,Screen.height*0.65,100,50), "Hovering");
}
}
Interactor.js
var distance = 10;
var Interacting : boolean = true;
var Hovering : boolean = true;
//When "Interact" button is pressed do function Interact...
function Update(){
Hover();
if (Input.GetButtonDown("Interact")){
Interact();
}
}
//Raycast
function Interact(){
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 20));
if (Physics.Raycast (ray, hit, distance)){
hit.transform.SendMessage("Interact", Interacting, SendMessageOptions.DontRequireReceiver);
}
}
//Raycast
function Hover(){
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 20));
if (Physics.Raycast (ray, hit, distance)){
hit.transform.SendMessage("Hovers", Hovering, SendMessageOptions.DontRequireReceiver);
}
}