Skip to content

Instantly share code, notes, and snippets.

@craigmjohnston
Last active August 3, 2016 15:52
Show Gist options
  • Save craigmjohnston/d9d4927d6a17600d409634d9892e6336 to your computer and use it in GitHub Desktop.
Save craigmjohnston/d9d4927d6a17600d409634d9892e6336 to your computer and use it in GitHub Desktop.
class Plant : MonoBehaviour {
Sprite sprite;
float growTime;
AudioClip sfx;
void Start() {
StartCoroutine(WaitForSeconds(growTime));
}
IEnumerator WaitForSeconds Grow(float duration) {
yield return new WaitForSeconds(duration);
OnFinishedGrowing();
}
virtual void OnFinishedGrowing() { }
}
class MoneyPlant : Plant {
double rewardMoney;
override void OnFinishedGrowing() {
// todo give the player rewardMoney
}
}
class SeedsPlant : Plant {
int rewardSeeds;
override void OnFinishedGrowing() {
// todo give the player rewardSeeds
}
}
class PlantSpawner : MonoBehaviour {
enum PlantType {
Carrot, Parsnip, Potatoes
}
MoneyPlant moneyPlantPrefab;
SeedsPlant seedsPlantPrefab;
Sprite carrotSprite;
Sprite parsnipSprite;
Sprite potatoesSprite;
void SpawnPlant(PlantType type) {
Plant plant = null;
switch (type) {
case Carrot:
plant = Instantiate(moneyPlantPrefab);
plant.sprite = carrotSprite;
plant.growTime = 10;
// ... etc.
break;
case Parsnip:
plant = Instantiate(seedsPlantPrefab);
plant.sprite = parsnipSprite;
plant.growTime = 5;
// ... etc.
break;
case Potatoes:
plant = Instantiate(moneyPlantPrefab);
plant.sprite = potatoesSprite;
plant.growTime = 30;
// ... etc.
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment