Created
April 23, 2015 05:11
-
-
Save OutlawGameTools/11ab114c8bdcf076d51a to your computer and use it in GitHub Desktop.
CS109 - Add force to a game object when mouse button is pressed; stop adding when button is up.
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