Skip to content

Instantly share code, notes, and snippets.

@geta6
Created October 21, 2011 09:18
Show Gist options
  • Save geta6/1303425 to your computer and use it in GitHub Desktop.
Save geta6/1303425 to your computer and use it in GitHub Desktop.
Input.GetButton Method
var bulletPrefab : GameObject;
var initialVelocity : float;
function Update () {
if (Input.GetButton("Fire1")) {
var screenPoint = Input.mousePosition;
screenPoint.z = 10.0;
Instantiate(bulletPrefab, transform.position, transform.rotation).rigidbody.velocity
= ((camera.ScreenToWorldPoint(screenPoint)) - transform.position).normalized * initialVelocity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment