public void CreateThings(bool deathmatch) { GameObject holder = new GameObject("MapThings"); holder.transform.SetParent(transform); foreach (Thing t in MapLoader.things) { if (!deathmatch) { if ((t.flags & (1 << 4)) != 0) { continue; } } if (!_things.ContainsKey(t.thingType)) { Debug.Log("Unknown thing type (" + t.thingType + ")"); continue; } GameObject thingObject = Instantiate(_things[t.thingType]); thingObject.transform.SetParent(holder.transform); ThingController tc = thingObject.GetComponent <ThingController>(); if (tc != null) { tc.thing = t; tc.Init(); activeThings.Add(tc); } } }
public void CreateThings(bool deathmatch) { GameObject holder = new GameObject("MapThings"); holder.transform.SetParent(transform); foreach (Thing t in MapLoader.things) { if (!deathmatch) { if ((t.flags & (1 << 4)) != 0) { continue; } } if (!thingPrefabs.ContainsKey(t.thingType)) { Debug.Log("Unknown thing type (" + t.thingType + ")"); continue; } GameObject thingObject = Instantiate(thingPrefabs[t.thingType]); thingObject.transform.SetParent(holder.transform); ThingController tc = thingObject.GetComponent <ThingController>(); if (tc != null) { tc.transform.position = new Vector3(t.posX, 0, t.posY); //height will be set by tc.Init() tc.transform.rotation = Quaternion.Euler(0, t.facing, 0); tc.Init(); if ((t.flags & (1 << 3)) != 0) { if (tc.CurrentBehavior != null) { tc.CurrentBehavior.deaf = true; } } } } }
public void Damage(int amount, DamageType damageType = DamageType.Generic, GameObject attacker = null) { if (dead) { return; } if (CurrentBehavior != null) { CurrentBehavior.ModifyDamage(ref amount, damageType); } if (amount <= 0) { return; } hitpoints -= amount; if (hitpoints <= 0) { moveVector = Vector3.zero; gameObject.layer = 14; //ragdoll dead = true; if (DieFrames.Length > 0) { frametime = 0f; frameindex = 0; refreshSprite = true; SetSprite(DieFrames[0]); } if (DieSounds.Length > 0) { audioSource.Stop(); audioSource.clip = DieSounds[Random.Range(0, DieSounds.Length)]; audioSource.Play(); } //change type into decoration RemoveFromGrid(); thingType = ThingType.Decor; AddToGrid(); if (dropOnDeath != null) { ThingController loot = Instantiate(dropOnDeath); loot.transform.position = transform.position + transform.forward * .1f; loot.transform.rotation = transform.rotation; loot.Init(); loot.transform.SetParent(GameManager.Instance.TemporaryObjectsHolder); } return; } if (Random.value <= PainChance) { if (painTime < .1f) { if (PainSounds.Length > 0) { audioSource.Stop(); audioSource.clip = PainSounds[Random.Range(0, PainSounds.Length)]; audioSource.Play(); } } painTime = _PainTime; if (PainFrames.Length > 0) { frameindex = 0; frametime = 0f; refreshSprite = true; SetSprite(PainFrames[0]); } } CurrentBehavior.alert = true; //alert nearby enemies, since sound won't propagate here if (attacker != null) { if (attacker.GetComponent <PlayerThing>() != null) { if (GameManager.Instance.Player[0].playerBreath.GetBreath(cell) == null) { BreathArea alarmBreath = new BreathArea(15); alarmBreath.position = cell; List <ThingController> monsters = new List <ThingController>(); AI.FillBreath(ref alarmBreath, ref monsters, true); foreach (ThingController tc in monsters) { if (tc.CurrentBehavior != null) { tc.CurrentBehavior.AlertByNoise(); } } } } } }