diff --git a/Assets/Prefabs/Enemies/Hellephant.prefab b/Assets/Prefabs/Enemies/Hellephant.prefab index bf16dae58566b71a265d382929b86b6bf94edbbb..c62bf26b982ec8e661614fad6eeab9c260e2234a 100644 --- a/Assets/Prefabs/Enemies/Hellephant.prefab +++ b/Assets/Prefabs/Enemies/Hellephant.prefab @@ -10270,6 +10270,7 @@ MonoBehaviour: timeBetweenAttacks: 0.75 initialDamage: 10 attackDamage: 30 + shotgunEnemyShooting: {fileID: 7622203168288361851} --- !u!114 &-9152102147166215733 MonoBehaviour: m_ObjectHideFlags: 0 @@ -10607,13 +10608,50 @@ PrefabInstance: propertyPath: m_Layer value: 7 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 7336751061594590231, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 788510959643943715, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} + insertIndex: -1 + addedObject: {fileID: 7622203168288361851} m_SourcePrefab: {fileID: 100100000, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} +--- !u!1 &1708040745082926560 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 788510959643943715, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} + m_PrefabInstance: {fileID: 2109220129360041667} + m_PrefabAsset: {fileID: 0} +--- !u!114 &7622203168288361851 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1708040745082926560} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 83c3268d7aa0e744993bbc7d8f14d60f, type: 3} + m_Name: + m_EditorClassIdentifier: + damagePerShot: 40 + originDamage: 40 + timeBetweenBullets: 0.5 + range: 7.5 + faceLight: {fileID: 6990121572900354302} + bullet: {fileID: 2441078129812255352} +--- !u!1 &2441078129812255352 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 4369906883959776443, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} + m_PrefabInstance: {fileID: 2109220129360041667} + m_PrefabAsset: {fileID: 0} --- !u!4 &6257198256476185781 stripped Transform: m_CorrespondingSourceObject: {fileID: 5445832859186049654, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} m_PrefabInstance: {fileID: 2109220129360041667} m_PrefabAsset: {fileID: 0} +--- !u!108 &6990121572900354302 stripped +Light: + m_CorrespondingSourceObject: {fileID: 8954442493623987773, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} + m_PrefabInstance: {fileID: 2109220129360041667} + m_PrefabAsset: {fileID: 0} diff --git a/Assets/Prefabs/Enemies/ZomBunny Leader.prefab b/Assets/Prefabs/Enemies/ZomBunny Leader.prefab index a1e2d6a1b5233de53d30b86b6654bec7ab2b8539..578c22411bc172fab20247e808c6d23dca714072 100644 --- a/Assets/Prefabs/Enemies/ZomBunny Leader.prefab +++ b/Assets/Prefabs/Enemies/ZomBunny Leader.prefab @@ -262,6 +262,7 @@ MonoBehaviour: timeBetweenAttacks: 0.5 initialDamage: 10 attackDamage: 10 + shotgunEnemyShooting: {fileID: 4695188030650641114} --- !u!114 &11400002 MonoBehaviour: m_ObjectHideFlags: 0 @@ -10422,11 +10423,48 @@ PrefabInstance: propertyPath: m_Layer value: 7 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 7336751061594590231, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 788510959643943715, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} + insertIndex: -1 + addedObject: {fileID: 4695188030650641114} m_SourcePrefab: {fileID: 100100000, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} +--- !u!1 &307164678053217829 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 4369906883959776443, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} + m_PrefabInstance: {fileID: 4100038787078038174} + m_PrefabAsset: {fileID: 0} +--- !u!1 &3609381146599113149 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 788510959643943715, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} + m_PrefabInstance: {fileID: 4100038787078038174} + m_PrefabAsset: {fileID: 0} +--- !u!114 &4695188030650641114 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3609381146599113149} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 83c3268d7aa0e744993bbc7d8f14d60f, type: 3} + m_Name: + m_EditorClassIdentifier: + damagePerShot: 40 + originDamage: 40 + timeBetweenBullets: 0.5 + range: 7.5 + faceLight: {fileID: 4945745742565395619} + bullet: {fileID: 307164678053217829} +--- !u!108 &4945745742565395619 stripped +Light: + m_CorrespondingSourceObject: {fileID: 8954442493623987773, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} + m_PrefabInstance: {fileID: 4100038787078038174} + m_PrefabAsset: {fileID: 0} --- !u!4 &8319625895022366952 stripped Transform: m_CorrespondingSourceObject: {fileID: 5445832859186049654, guid: c875da102be376d4a9f9cabc41b48b24, type: 3} diff --git a/Assets/Scenes/Level01.unity b/Assets/Scenes/Level01.unity index d82aa37f9f3005f92c21d05c02dd9384455a0508..c9bbeec0775ff33d4e5942f651a5e5805dee4085 100644 --- a/Assets/Scenes/Level01.unity +++ b/Assets/Scenes/Level01.unity @@ -456,8 +456,8 @@ GameObject: - component: {fileID: 14871711} - component: {fileID: 14871710} - component: {fileID: 14871709} - - component: {fileID: 14871713} - component: {fileID: 14871714} + - component: {fileID: 14871713} m_Layer: 0 m_Name: EnemyManager m_TagString: Untagged @@ -15148,6 +15148,10 @@ PrefabInstance: propertyPath: m_Name value: Player objectReference: {fileID: 0} + - target: {fileID: 100078, guid: f1d84cc28597f5641a3d9cbc4df7e306, type: 3} + propertyPath: m_Layer + value: 6 + objectReference: {fileID: 0} - target: {fileID: 100078, guid: f1d84cc28597f5641a3d9cbc4df7e306, type: 3} propertyPath: m_IsActive value: 1 diff --git a/Assets/Scripts/Enemy/EnemyAttack.cs b/Assets/Scripts/Enemy/EnemyAttack.cs index d152e4571d263b0aca06b4876b0a10d7e9d3a521..663719b31792ac67cc6c8678ef0b611484fdaf75 100644 --- a/Assets/Scripts/Enemy/EnemyAttack.cs +++ b/Assets/Scripts/Enemy/EnemyAttack.cs @@ -16,6 +16,7 @@ namespace Nightmare GameObject player; PlayerHealth playerHealth; EnemyHealth enemyHealth; + public ShotgunEnemyShooting shotgunEnemyShooting; bool playerInRange; float timer; @@ -74,10 +75,16 @@ namespace Nightmare timer += Time.deltaTime; // If the timer exceeds the time between attacks, the player is in range and this enemy is alive... - if(timer >= timeBetweenAttacks && playerInRange && enemyHealth.CurrentHealth() > 0) + if(timer >= timeBetweenAttacks && enemyHealth.CurrentHealth() > 0) { // ... attack. - Attack (); + if (shotgunEnemyShooting) + { + // Calculate the distance between the enemy and the player + float distanceToPlayer = Vector3.Distance(transform.position, player.transform.position); + if (distanceToPlayer < 10) ShotgunAttack(); + } + else if (playerInRange) SwordAttack(); } // If the player has zero or less health... @@ -88,18 +95,35 @@ namespace Nightmare } } - void Attack () + void ShotgunAttack () { // Reset the timer. timer = 0f; // If the player has health to lose... if(playerHealth.currentHealth > 0) + { + // Rotate the enemy to face the player + transform.LookAt(player.transform.position); + + // ... damage the player. + shotgunEnemyShooting.Shoot(attackDamage); + } + } + + void SwordAttack() + { + // Reset the timer. + timer = 0f; + + // If the player has health to lose... + if (playerHealth.currentHealth > 0) { // ... damage the player. + // If sword if (swordAnim) swordAnim.SetTrigger("Attack"); if (swordAudio) swordAudio.Play(); - playerHealth.TakeDamage (attackDamage); + playerHealth.TakeDamage(attackDamage); } } } diff --git a/Assets/Scripts/Weapon/ShotgunEnemyShooting.cs b/Assets/Scripts/Weapon/ShotgunEnemyShooting.cs new file mode 100644 index 0000000000000000000000000000000000000000..e0919c4399faee2c2561b4308dd7da19936f9a83 --- /dev/null +++ b/Assets/Scripts/Weapon/ShotgunEnemyShooting.cs @@ -0,0 +1,119 @@ +using Nightmare; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ShotgunEnemyShooting : PausibleObject +{ + public float timeBetweenBullets = 0.5f; + public float range = 7.5f; + + float timer; + Ray shootRay = new Ray(); + RaycastHit shootHit; + int shootableMask; + private LineRenderer[] gunLines; + AudioSource gunAudio; + Light gunLight; + public Light faceLight; + float effectsDisplayTime = 0.2f; + private GameObject[] bullets; + [SerializeField] private GameObject bullet; + + + void Awake() + { + shootableMask = LayerMask.GetMask("Shootable"); + gunAudio = GetComponent<AudioSource>(); + gunLight = GetComponent<Light>(); + + for (int i = 0; i < 10; i++) + { + Instantiate(bullet, transform); + } + + bullets = new GameObject[10]; + gunLines = new LineRenderer[10]; + + for (int i = 0; i < 10; i++) + { + bullets[i] = transform.GetChild(i).gameObject; + gunLines[i] = bullets[i].GetComponent<LineRenderer>(); + } + + StartPausible(); + } + + void OnDestroy() + { + StopPausible(); + } + + void Update() + { + if (isPaused) return; + timer += Time.deltaTime; + + if (timer >= timeBetweenBullets * effectsDisplayTime) + { + DisableEffects(); + } + } + + public void DisableEffects() + { + // Disable the line renderer and the light. + for (int i = 0; i < 10; i++) + { + gunLines[i].enabled = false; + } + faceLight.enabled = false; + gunLight.enabled = false; + } + + public void Shoot(double attackDamage) + { + // Reset the timer. + timer = 0f; + + gunAudio.Play(); + + // Enable the lights. + gunLight.enabled = true; + faceLight.enabled = true; + + // Set the shootRay + for (int i = 0; i < 5; i++) + { + + gunLines[i].enabled = true; + gunLines[i].SetPosition(0, bullets[i].transform.position); + + shootRay.origin = bullets[i].transform.position; + shootRay.direction = Quaternion.AngleAxis((i - 2) * 60 / 10, new Vector3(0, 1, 0)) * bullets[i].transform.forward; + + // Perform the raycast against gameobjects on the shootable layer and if it hits something... + if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) + { + // Try and find an PlayerHealth script on the gameobject hit. + PlayerHealth playerHealth = shootHit.collider.GetComponent<PlayerHealth>(); + + if (playerHealth != null) + { + // the damage taken is based on the distance from the player to the enemy + double damage = attackDamage - Vector3.Distance(transform.position, playerHealth.transform.position); + playerHealth.TakeDamage(damage); + } + + // Set the second position of the line renderer to the point the raycast hit. + gunLines[i].SetPosition(1, shootHit.point); + } + // If the raycast didn't hit anything on the shootable layer... + else + { + // ... set the second position of the line renderer to the fullest extent of the gun's range. + gunLines[i].SetPosition(1, shootRay.origin + shootRay.direction * range); + } + } + } +} diff --git a/Assets/Scripts/Weapon/ShotgunEnemyShooting.cs.meta b/Assets/Scripts/Weapon/ShotgunEnemyShooting.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..b0c33b7d779c3eca51aba3f299a75cb133b534eb --- /dev/null +++ b/Assets/Scripts/Weapon/ShotgunEnemyShooting.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 83c3268d7aa0e744993bbc7d8f14d60f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: