- Home /
How do I call a script or a function to be active 'while'a GUITexture is displayed?
I must start by apologising the lack of convention within my script. I have never studied any programming language and I am trying to teach myself the basics of UnityScript.
What I have is a function called Freeze which disables character movement and mouse look scripts.
This works perfectly when combining a RaycastHit with a GetKey. This then displays a button that can be clicked which on doing so displays the GUITexture.
What I need is for the Freeze function to be called while the GUITexture is onscreen, preventing any inadvertent movement of the character.
Here is my script so far.
#pragma strict
function Freeze(){
Screen.showCursor = true;
var ml = GameObject.Find("Main Camera");
GetComponent(MouseLook).enabled = false;
ml.GetComponentInChildren(MouseLook).enabled = false;
GetComponent(FPSInputController).enabled = false;
GetComponent(CharacterMotor).enabled = false;
}
function UnFreeze(){
var ml = GameObject.Find("Main Camera");
Screen.showCursor = false;
GetComponent(MouseLook).enabled = true;
ml.GetComponentInChildren(MouseLook).enabled = true;
GetComponent(FPSInputController).enabled = true;
GetComponent(CharacterMotor).enabled = true;
}
function OnGUI(){
var go = GameObject.Find("InfoScreen");
go.GetComponent(MyGUI).enabled = true;
}
function offGUI () {
var go = GameObject.Find("InfoScreen");
go.GetComponent(MyGUI).enabled = false;
}
function Start () {}
var linkToInfoBox : InfoBox;
function Update () {
var go = GameObject.Find("InfoScreen");
Screen.showCursor = false;
var ray : Ray = Camera.main.ViewportPointToRay(Vector3(0.5,0.5,0));
var Hit : RaycastHit;
//var ray = Camera.main.ScreenPointToRay;//(Input.mousePosition);
go.GetComponent(MyGUI).enabled = false;
go.GetComponent(InfoBox).enabled = false;
var texup = go.GetComponent(GUITexture).enabled;
Debug.DrawRay(ray.origin, ray.direction * 5, Color.cyan);
if(Input.GetKey(KeyCode.F))
{
Freeze();
}
else
{
UnFreeze();
}
for(Hit in Physics.RaycastAll(ray.origin, ray.direction, 5))
{
if(Hit.transform.name == "BigTree")
{
OnGUI();
Debug.DrawRay(ray.origin, ray.direction * 5, Color.red);
if((Hit.transform.name == "BigTree") && (Input.GetKey(KeyCode.E)))
{
Screen.showCursor = true;
Freeze();
go.GetComponent(InfoBox).enabled = true;
offGUI();
//linkToInfoBox.OnGUI ();
}
else
{
UnFreeze();
}
// GetComponent(Freeze).enabled = false;
// tex.GetComponent(GUITexture).enabled = false;
// }
}
}
if (Input.GetMouseButtonDown(0))
{
go.GetComponent(GUITexture).enabled = false;
}
}
The InfoBox script is as follows
#pragma strict
var linkToInfoRaycast : InfoRaycast;
function OnInfoGUI()
{
var onTex = GetComponent(GUITexture).enabled;
//var mygui = GetComponentInChildren(MyGUI).enabled;
GUI.Label (Rect (400, 140, 300, 140), "Text");
if (GUI.Button (Rect (400,300,150,50), "Click for information"))
{
GetComponent(GUITexture).enabled = true;
GUI.Label(Rect(500, 300, 300, 40), "Click to exit");
}
}
I have tried using an If statement nested inside the button that says if ( GetComponent(GUITexture).enabled = true) but this does not work as I sure you are all well aware.
While loops caught my attention but I have not been able to set the conditions correctly for this either.
If anyone has an idea where I might be able to call the Freeze function while the GUITexture component is active I would be very grateful to hear.
Apologies again for the messy script.
Your answer
![](https://koobas.hobune.stream/wayback/20220613150840im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
javascript equivalent of Action? 0 Answers
Performance Optimization ~Function Update: Loop or Once ? 5 Answers
Call GUITexture and script 1 Answer
Need help with If/else statement. 1 Answer