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);  





//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);


When you touch an area in the Rect, a particle is instantiated.

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.