void OnDestroy() { if (bin == this) { bin = null; } }
// Use this for initialization void Start() { if (bin == null) { bin = this; } }
internal void RemoveGarbage(Garbages garbageType, int cost) { //this is used for removing garbage to make a spell if (Scores.ContainsKey(garbageType)) { Scores[garbageType] -= cost; } }
public static void GenGarbage() { if (Garbages.bin == null) { GameObject garbage = new GameObject(); Garbages garbages = garbage.AddComponent <Garbages>(); Garbages.bin = garbages; } }
// returns the number of picked up garbage of a certain type. public int GetScore(Garbages garbageType) { if (!Scores.ContainsKey(garbageType)) { return(0); } else { return(Scores[garbageType]); } }
public void Fire(Garbages garbageType) // fires a spell from a certain type { if (Context.Data.GetScore(garbageType) >= Context.Data.MagicCost) // if we have enough resources { Context.Data.RemoveGarbage(garbageType, Context.Data.MagicCost); Context.Data.Player.StartMagic(garbageType); } else { NotEnoughGarbage(garbageType); // if the resources are not enough shows a message } }
internal void StartMagic(Garbages spellType) { // first specifies the spell game object based on the user selection SelectedSpell = PlasticSpell; if (spellType == Garbages.Metal) { SelectedSpell = MetalSpell; } else if (spellType == Garbages.Paper) { SelectedSpell = PaperSpell; } if (!anim.GetBool("isJumping")) { anim.SetBool("isMagic", true); //showing the magic animation } }
//adds score for picking up garbage public void AddScore(Garbages garbageType) { TotalScore += BaseScore; if (!Scores.ContainsKey(garbageType)) { Scores.Add(garbageType, BaseScore); } else { Scores[garbageType] += BaseScore; } PlayerPrefs.SetInt("LastScore", TotalScore); if (PlayerPrefs.HasKey("HighestScore")) { if (PlayerPrefs.GetInt("HighestScore") < TotalScore) { PlayerPrefs.SetInt("HighestScore", TotalScore); } } else { PlayerPrefs.SetInt("HighestScore", TotalScore); } }
public void NotEnoughGarbage(Garbages garbageType) // message for not having enough resources { Context.Data.Message = "You don't have enough " + garbageType; }