Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // min and max times for type change
- public var minTypeChange : int = 10;
- public var maxTypeChange : int = 30;
- //min and max rotatio speed
- public var minRotationSpeed : float = 0.5;
- public var maxRotationSpeed : float = 2.0;
- //calculated rotation speed
- private var rotationSpeed : float;
- //textfield to hold the score and score variable
- private var textfield : GUIText;
- private var score : int;
- public var Pickup : GameObject;
- private var SpawnPickup : GameObject;
- private var spawnIndexAvailableList;
- private var PickupCollected;
- function UpdateScoreText()
- {
- //update textfield with score
- textfield.text = score.ToString();
- }
- function Update()
- {
- // rotate the gameobject every frame
- transform.Rotate(rotationSpeed, rotationSpeed, 0);
- }
- function Start()
- {
- while (true)
- {
- //wait for x seconds
- yield WaitForSeconds(Random.Range(minTypeChange, maxTypeChange));
- // set a random type
- SwapType();
- }
- }
- function Awake()
- {
- textfield = GameObject.Find("GUI/txt-Score").GetComponent(GUIText);
- score = 0;
- UpdateScoreText();
- // calculate a random rotation speed
- rotationSpeed = Random.Range(minRotationSpeed, maxRotationSpeed);
- // set a random type to begin
- SwapType();
- }
- function SwapType()
- {
- // generate a random number between 1 and 10
- var random : float = Random.Range(1, 10);
- // set the type
- if (random <= 5) // 50% for type 1
- {
- type = 1;
- }
- else if (random <= 8) // 30% for type 2
- {
- type = 2;
- }
- else // 20% for type 3
- {
- type = 3;
- }
- }
- function Collected(PickUpCollected : GameObject)
- {
- // retrieve name of the collected pick up and cast int
- var index : int = parseInt(PickUpCollected.name);
- //retrieve the pickup state
- var type : int = PickUpCollected.GetComponent(PickUp).type;
- //update the score depending on the type pickup
- if (type == 1)
- {
- score += 2; // add 2 to the score
- }
- else if (type == 2)
- {
- score += Random.Range(-2, 5); // add a random score between -2 and 5 to score
- }
- // update the score
- UpdateScoreText();
- // Adds Score, when the object is collected.
- ApplyScore(10);
- // destroy the pickup
- Destroy(PickUpCollected);
- }
- function ApplyScore(score : int)
- {
- Score += score;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement