Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
RTS/Assets/Buildings/Capacitor/Capacitor.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
65 lines (58 sloc)
1.71 KB
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
using UnityEngine; | |
using System.Collections; | |
using RTS; | |
public class Capacitor : Building { | |
public int addedCapacitanceLimit; | |
public Vector3 center; | |
public float radius; | |
private float angle; | |
public int maxWorkers; | |
private int currentworkers; | |
private Vector3 currentpoint; | |
private float step; | |
protected override void Awake() { | |
base.Awake (); | |
} | |
protected override void Start () { | |
base.Start (); | |
player.addResourceLimit (ResourceType.Capacitance, addedCapacitanceLimit); | |
center = transform.position; | |
step = 2 * Mathf.PI / maxWorkers; | |
angle = 0; | |
currentworkers = transform.childCount; | |
currentpoint = new Vector3 (center.x + radius, center.y, center.z + radius); | |
CreateUnit ("Worker"); | |
CreateUnit ("Worker"); | |
CreateUnit ("Worker"); | |
CreateUnit ("Worker"); | |
CreateUnit ("Worker"); | |
CreateUnit ("Worker"); | |
} | |
protected override void Update () { | |
base.Update (); | |
if (!constructing) { | |
} | |
} | |
protected override void OnGUI() { | |
base.OnGUI (); | |
} | |
protected override void OnDestroy() { | |
player.addResourceLimit (ResourceType.Capacitance, addedCapacitanceLimit * -1); | |
} | |
public void addResource(ResourceType resourceName, int value) { | |
player.addResource (resourceName, value); | |
} | |
public void addResourceLimit (ResourceType resourceName, int value) { | |
player.addResourceLimit (resourceName, value); | |
} | |
protected override void InstantiateUnit() { | |
if (currentworkers < maxWorkers) { | |
angle += step; | |
Vector3 offset = new Vector3 (Mathf.Sin (angle) * radius, 0, Mathf.Cos (angle) * radius); | |
currentpoint = center + offset; | |
Unit newUnit = Instantiate (buildQueue.Dequeue (), currentpoint, transform.rotation) as Unit; | |
newUnit.transform.parent = this.transform; | |
currentworkers++; | |
} | |
} | |
} |