void Start() { memory = (memory == null) ? GetComponent <AIMemory>() : memory; if (sounds.weaponSource == null) { SetWeaponSoundSource(); } }
public void Attack(GameObject overrideTarget = null) { if (number_of_allowed_attacks < 1) { return; } number_of_allowed_attacks -= 1; if (isDebugging == true) { Debug.Log(name + " attacked"); } AIMemory memory = GetComponent <AIMemory>(); GameObject target = null; if (overrideTarget == null) { target = memory.GetTarget(); } else { target = overrideTarget; } if (target == null) { return; } GameObject returnTarget = AIHelpers.InaccurateRaycast( target.transform, memory.GetEyes().transform, memory.GetIgnoreLayers(), memory.GetOffsetRange(), memory.GetInaccuracy(), memory.GetFireRange(), isDebugging ); PlayMuzzleFlash(); PlayWeaponSound(); if (returnTarget != null) { if (isDebugging == true) { Debug.Log(name + " sending damage to " + returnTarget.transform.root.name); } if (returnTarget.transform.root.GetComponent <Health>()) { returnTarget.transform.root.GetComponent <Health>().ApplyDamage(memory.GetRangeDamageAmount(), gameObject); } } }
public void BroadCastTargetPosition() { AIMemory memory = GetComponent <AIMemory>(); Vector3 position = memory.GetLastTargetPosition(); float distance = memory.GetShoutDistance(); string[] friendTags = memory.GetFriendTags(); GameObject[] friends = AIHelpers.GetAllGameObjectsInRange(friendTags, distance); foreach (GameObject friend in friends) { friend.GetComponent <AIMemory>().SetLastTargetPosition(position); friend.GetComponent <AIMemory>().SetIncreasedLevel(); } }