Ive made a script so when i click an object like an npc i can talk to it with different responses but when i go to touch the responses the GUI goes i would like it so when i let go, The GUI stays till i press the close button :). Any help would be greatly appreciated
var target : Transform;
function OnGUI () {
///making a varible i named it position it has to hav a lowercase first letter ive made it equal to a 2d position space by putting Vector2 and the (x,y) is the place im ref var position = Vector2(0,0);
/// mr cubies position is (x = 6.14779,y = 1)
var screenPosX : Vector3 = camera.WorldToScreenPoint (target.position);
print ("target is " + screenPosX.x + " pixels from the left");
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Stationary) {
var touchPositionXRounded = Mathf.Round(touch.position.x / 100);
var touchPositionYRounded = Mathf.Round(touch.position.y / 100);
// screen position of gameobject
var screenPosY : Vector3 = camera.WorldToScreenPoint (target.position);
print ("target is " + screenPosY.y + " pixels from the top");
var oSPX = Mathf.Round(screenPosX.x / 100);
var oSPY = Mathf.Round(screenPosY.y / 100);
/// Debug.Log(touch.position);
Debug.Log(touchPositionXRounded);
Debug.Log(touchPositionYRounded);
Debug.Log(oSPX);
Debug.Log(oSPY);
// if touch position = the touch position of game object display a gui box
if (touchPositionXRounded == oSPX){
if (touchPositionYRounded == oSPY) {
GUI.Box(Rect(10,10,100,90),"Hello");
if (GUI.Button(Rect(10,80,100,90),"Close")) {
touch == false;
}
// if you click the button it displays a gui text box over the old one
if (GUI.Button(Rect(120,10,150,40),"Hi")){
GUI.Box(Rect(10,10,100,90),"Hello");
}
if (GUI.Button(Rect(120,60,150,40),"Go away!")){
GUI.Box(Rect(10,10,100,90),"fine then moody :(");
}
}
}
}
}
}
EDIT ____ i added a boolean but still does not work
#pragma strict
var show : boolean;
var show2 : boolean;
var target : Transform;
var screenPosX : Vector3 = camera.WorldToScreenPoint (target.position);
print ("target is " + screenPosX.x + " pixels from the left");
var screenPosY : Vector3 = camera.WorldToScreenPoint (target.position);
print ("target is " + screenPosY.y + " pixels from the top");
// screen position of gameobject
var oSPX = Mathf.Round(screenPosX.x / 100);
var oSPY = Mathf.Round(screenPosY.y / 100);
if(show2 === true);
{
}
function Update () {
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
show = true;
Debug.Log("niceballsTrue");
Debug.Log(show);
var touchPositionXRounded = Mathf.Round(touch.position.x / 100);
var touchPositionYRounded = Mathf.Round(touch.position.y / 100);
}
else
{
show = false;
Debug.Log("False");
Debug.Log(show);
}
if(show === true)
{
Debug.Log("OMG IT WORKSish");
}
else if (touchPositionXRounded == oSPX)
{
if (touchPositionYRounded == oSPY) {
show2 = true;
}
Debug.Log("ITS ALIVE":)
}
else
{
Debug.Log("printed false :(");
}
}
}