Created
March 9, 2015 00:19
-
-
Save OutlawGameTools/18d4123f17052131e723 to your computer and use it in GitHub Desktop.
CS109 - Add force to a RigidBody2D when the mouse button is pressed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
public var rocket : GameObject; // object to push | |
public var xSpeed : float = 0; // horizontal speed | |
public var ySpeed : float = 400; // vertical speed | |
private var rb2D : Rigidbody2D; | |
function Start () | |
{ | |
rb2D = rocket.GetComponent.<Rigidbody2D>(); | |
} | |
function OnMouseDown () | |
{ | |
// add force to the object | |
rb2D.AddForce(new Vector2(xSpeed, ySpeed)); | |
} | |
function OnMouseUp () | |
{ | |
// stop adding force | |
rb2D.AddForce(Vector2.zero); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment