// when someone enters the objective region private void OnTriggerEnter2D(Collider2D collision) { GameObject go = collision.gameObject; PlayerBS pl = null; ZombieBS zm = null; if (go != null) { switch (objType) { case ObjType.WinLevel: pl = go.GetComponent <PlayerBS>(); if (pl != null) { bool hasAllItems = true; if (ReqItems.Count > 0) { foreach (ItemBS i in ReqItems) { if (false == pl.character.inventory.Contains(i)) { hasAllItems = false; } } } if (hasAllItems) { finishedObjective = true; } } break; case ObjType.QuitLevel: pl = go.GetComponent <PlayerBS>(); if (pl != null) { finishedObjective = true; } break; case ObjType.LoseLevel: zm = go.GetComponent <ZombieBS>(); if (zm != null) { finishedObjective = true; } break; default: break; } } }
// spawns a new zombie (and returns) public GameObject SpawnZombie(Vector2 spawnPoint) { GameObject zombie = Instantiate(prefabZombie, this.transform) as GameObject; ALL_CHARACTERS.Add(zombie); zombie.transform.position = spawnPoint; Character_BS zChar = zombie.GetComponent <Character_BS>(); zChar.health = (int)UnityEngine.Random.Range(60, 100); zChar.maxHealth = zChar.health; zChar.BaseWalkSpeed = UnityEngine.Random.Range(0.25f, 0.35f); zChar.BaseRunSpeed = zChar.BaseWalkSpeed * 1.5f; //zChar.items; does the zombie have some items ZombieBS zBS = zombie.GetComponent <ZombieBS>(); zBS.delayTime = UnityEngine.Random.Range(0.3f, 0.9f); // how long after going idle till they stop zBS.minIntensity = UnityEngine.Random.Range(0.5f, 1f); // how likely to respond to minor sounds zBS.hardDetectRange = UnityEngine.Random.Range(1.5f, 2f); // how close before hard target return(zombie); }