- Home /
What does this cript do?
Know that this is perhaps an odd question to ask but what does this script do?
//variables which construct the Rectangle
var Rect = Rect(Screen.width,Screen.height,Screen.width,Screen.height);
var HorizontalPositionx : float;
var VerticalPositiony : float;
var Width : float;
var Height : float;
var particle : GameObject;
var custom : GUIStyle;
function Update(){
Rect.y = Screen.height/VerticalPositiony;
Rect.x = Screen.width/HorizontalPositionx;
Rect.height = Screen.height/Height;
Rect.width = Screen.width/Width;
if (Rect.Contains(Input.mousePosition)){
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
// Create a particle if hit
Instantiate (particle, transform.position, transform.rotation);
Application.LoadLevel(0);
}
}
}
//you can edit this to show whatever your button is later but for now this just shows where your rect is
function OnGUI(){
GUI.Box(Rect, "Button Rect", custom);
}
Answer by Bunny83 · Sep 25, 2011 at 04:09 PM
What the script does? - well, a lot senseless and strange things:
The whole rectangle setup doesn't make any sense. HorizontalPositionx, VerticalPositiony, Width and Height doesn't reflect pixel or viewport coordinates. They follow an
1/x
- behaviour which is kinda useless.I don't worked much with iPhone / Android but as far as i know Input.mousePosition won't work there. That's why you have the Touch-class. Using both methods will probably prevent the code inside the if from ever being executed. Furthermore the Touch class is not available at other platforms so you can't even create a build for them.
The particle generation seems right so far, but executing LoadLevel right after Instantiate makes the Instantiate call useless since all scene objects are deleted after the new level has been loaded.
Ok, can you tell me how I can make it work? so when I click on a GUI or 3d text or something on an Android/IOS a scene will load...
the only thing I want to work is when I click on a a text in a menu on a phone a scene will load.
Answer by unluckyBastard · Sep 25, 2011 at 02:57 PM
When you touch an area in the Rect, a particle is instantiated.
Can you be more specific?
What happens? I mean, how does this work... do I haft to add this script to the main camera and then add an gui text or what?