Created
April 4, 2015 05:39
-
-
Save OutlawGameTools/164c577d67ba8280d12c to your computer and use it in GitHub Desktop.
CS109 - Attach to the rocket to allow firing, exploding, and resetting.
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 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; | |
public var removeOnInvisible : boolean = true; | |
private var gData : GameData; | |
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; | |
} | |
gData = GameObject.Find("SceneManager").GetComponent.<GameData>(); | |
} | |
function OnBecameInvisible() | |
{ | |
if (transform.position.x > 7.0) | |
{ | |
gData.numMissed++; | |
gData.DisplayScore(); | |
} | |
if (removeOnInvisible) | |
Destroy(gameObject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment