- Home /
Question by
abraham5361 · Sep 28, 2015 at 06:41 AM ·
pauseexitgraphics.drawtexture
Pause Button does completely different things than i wrote
So what I wrote in my code is this, first in the top right corner there will be a pause icon, when someone touches it it birngs up 4 Graphics.drawtexture textures: Backround,Box(<--These two ignore them they are just for design), Resume and Exit button. Also resume and exit buttons works.When player clicks resume he gets back to the game,when he clicks exit he goes to main menu.
My problem the pause button is instead showing the 4 Graphics.drawtexture textures and activates exit and resume button, It acts like its the exit button that sends player back to main menu(but I DONT mean it crashes the game), I am 100% postive with my code, here is the code with comments to explain.
using UnityEngine;
using System.Collections;
public class Pause : MonoBehaviour {
//For Textures
public Texture pause;
public Texture Box;
public Texture Exit;
public Texture resume;
public Texture Backround;
//This varibale is for decting a touch
public static int currTouch = 0;
//Button postions are stored in Rect variables
public Rect PauseP = new Rect(10, 10, 70, 70);
public Rect ExitP = new Rect(545, 350, 250, 66);
public Rect resumeP = new Rect(545, 240, 250, 66);
//For checking if the pause button is clicked
private float PauseT = 1;
void OnGUI() {
//For to draw the pause icon
Graphics.DrawTexture (new Rect (10, 10, 70, 70), pause);
if (PauseT == 2) {
//if Pause icon was clicked its float vaule will turn into 2 and draw the following textures
Graphics.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), Backround);
Graphics.DrawTexture (new Rect (445, 180, 450, 325), Box);
Graphics.DrawTexture (new Rect (545, 245, 250, 66), resume);
Graphics.DrawTexture (new Rect (545, 350, 250, 66), Exit);
}
//To detect touch /
if (Input.touches.Length <= 0) {
}
else {
for (int i = 0; i < Input.touchCount; i++) {
currTouch = i;
// Here stops touch detecting
//this part for checking touch postion
Vector2 Pos = Input.GetTouch (i).position;
Pos.y = Screen.height - Pos.y;
//If pause icon is touched
if (PauseP.Contains(Pos)) {
PauseT = 2;
}
if (PauseT == 2) {
//If PauseT = 2 then the following will work
//If exit was clicked
if (ExitP.Contains(Pos)) {
//This Variable tells the load scene what to load
Load.LW = 0;
//This code opens the load sence
Application.LoadLevel (3);
}
//if resume was clicked
if (resumeP.Contains(Pos)) {
PauseT = 1;
}
}
}
}
}
}
Comment