Skip to content

Instantly share code, notes, and snippets.

@OutlawGameTools
Created March 11, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OutlawGameTools/095cf6c1ff30e27d7997 to your computer and use it in GitHub Desktop.
Save OutlawGameTools/095cf6c1ff30e27d7997 to your computer and use it in GitHub Desktop.
CS109 - A better version of MoveObject that adds randomness and is more generic.
#pragma strict
public var xSpeed : int;
public var ySpeed : int;
public var randomX : boolean = false;
public var minXSpeed : int = 100;
public var maxXSpeed : int = 200;
public var randomY : boolean = false;
public var minYSpeed : int = 100;
public var maxYSpeed : int = 200;
public var resize : boolean = true;
public var minSize : float = 0.6f;
public var maxSize : float = 1f;
function Start ()
{
if (randomX)
xSpeed = Random.Range(minXSpeed, maxXSpeed);
if (randomY)
ySpeed = Random.Range(minYSpeed, maxYSpeed);
var newSpeed : Vector2;
newSpeed.x = xSpeed;
newSpeed.y = ySpeed;
GetComponent.<Rigidbody2D>().AddForce(newSpeed);
if (resize)
{
var newSize = Random.Range(minSize, maxSize);
gameObject.transform.localScale.x = newSize;
gameObject.transform.localScale.y = newSize;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment