Last active
August 3, 2016 15:52
-
-
Save craigmjohnston/d9d4927d6a17600d409634d9892e6336 to your computer and use it in GitHub Desktop.
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
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 | |
} | |
} |
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
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