- Home /
 
               Question by 
               BZS · Jan 31, 2014 at 11:51 PM · 
                javascriptinstantiateprefabgrid  
              
 
              Instantiate prefab within parameters?(Javascript)
I have this script that lets you spawn a prefab in a grid pattern whenever you click. How would I make it so that you can only spawn the prefab within certain parameters(between certain X and Y values)? Here is my script:
 var Block:GameObject;
 var squareSize : float = 1.0f;
 function Update ()
 {
     if (Input.GetMouseButtonDown(0)) 
     {
         var mousePos : Vector3 = Input.mousePosition;
         mousePos.z = 12.48309;
  
         var objectPos : Vector3 = Camera.main.ScreenToWorldPoint(mousePos);
 
         objectPos.x = Mathf.Round(objectPos.x/squareSize) * squareSize;
         objectPos.y = Mathf.Round(objectPos.y/squareSize) * squareSize;
         objectPos.z = Mathf.Round(objectPos.z/squareSize) * squareSize;
 
         Instantiate(Block, objectPos, Quaternion.identity);
     }
 }
Thanks in advanced!
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                