Cube Spawner

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by Tri3)
Line 1: Line 1:
 +
This script spawns cubes on plane (y=0), where user presses the mouse button.
  
 +
<pre>
 +
var plane : Plane = new Plane(Vector3.up, Vector3.zero);;
 +
 +
function LateUpdate()
 +
{
 +
  if (Input.GetMouseButton(0))
 +
  {
 +
      var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 +
 +
      var ent : float = 100.0;
 +
      if (plane.Raycast(ray, ent))
 +
      {
 +
        Debug.Log("Plane Raycast hit at distance: " + ent);
 +
        var hitPoint = ray.GetPoint(ent);
 +
       
 +
        var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
 +
        go.transform.position = hitPoint;
 +
        Debug.DrawRay (ray.origin, ray.direction * ent, Color.green);
 +
      }
 +
      else
 +
        Debug.DrawRay (ray.origin, ray.direction * 10, Color.red);
 +
 +
  }
 +
}
 +
</pre>

Revision as of 19:17, 19 October 2009

This script spawns cubes on plane (y=0), where user presses the mouse button.

var plane : Plane = new Plane(Vector3.up, Vector3.zero);;

function LateUpdate()
{
   if (Input.GetMouseButton(0))
   {
      var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

      var ent : float = 100.0;
      if (plane.Raycast(ray, ent))
      {
         Debug.Log("Plane Raycast hit at distance: " + ent);
         var hitPoint = ray.GetPoint(ent);
         
         var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
         go.transform.position = hitPoint;
         Debug.DrawRay (ray.origin, ray.direction * ent, Color.green);
      }
      else
         Debug.DrawRay (ray.origin, ray.direction * 10, Color.red);

   }
} 
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox