Cube Spawner

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Joseph05408 (Talk); changed back to last version by Tri3)
m
 
Line 1: Line 1:
 +
{{Stub}}
 +
 +
 
This script spawns cubes on plane (y=0), where user presses the mouse button.
 
This script spawns cubes on plane (y=0), where user presses the mouse button.
  

Latest revision as of 17:15, 11 December 2012

This article is a stub.

You can help UnifyWiki by expanding it.


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