Game Development Reference
In-Depth Information
Fig 2.31 A stack of duplicated cubes,
all with Rigidbodies.
Step 13. In the Project, create a new JavaScript file and call it fire .
Open it in the script editor and enter the code in Listing 2.12 . Save
the script and attach it to the Main Camera.
Listing 2.12 Script to Create a Sphere as a Projectile
on a Left Mouse Click
function Update ()
{
if(Input.GetButtonDown("Fire1"))
{
var ray:Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var sphere:GameObject =
GameObject.
CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = ray.origin;
sphere.AddComponent ("Rigidbody");
sphere.rigidbody.AddForce(ray.direction * 1000);
}
}
Search Nedrilad ::




Custom Search