From a608a6f9041ae335fbc87b71c3aa1b004f615b6a Mon Sep 17 00:00:00 2001 From: hab Date: Fri, 14 Apr 2023 03:16:04 +0200 Subject: [PATCH 1/4] Player Script --- Assets/Scenes/GameScene.unity | 50 +++++++- Assets/Scripts/GameManager.cs | 4 +- Assets/Scripts/Player/PlayerAudio.cs | 43 +++++++ Assets/Scripts/Player/PlayerAudio.cs.meta | 11 ++ Assets/Scripts/Player/PlayerMovement.cs | 36 +++--- Assets/Scripts/Player/PlayerRotation.cs | 20 ++++ Assets/Scripts/Player/PlayerRotation.cs.meta | 11 ++ Assets/Scripts/Player/SpawnPlayer.cs | 119 ++++--------------- Assets/Scripts/Zombie/ZombieSpawner.cs | 2 +- 9 files changed, 174 insertions(+), 122 deletions(-) create mode 100644 Assets/Scripts/Player/PlayerAudio.cs create mode 100644 Assets/Scripts/Player/PlayerAudio.cs.meta create mode 100644 Assets/Scripts/Player/PlayerRotation.cs create mode 100644 Assets/Scripts/Player/PlayerRotation.cs.meta diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 95bc620..6323ec3 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -1161,6 +1161,9 @@ GameObject: - component: {fileID: 742329080} - component: {fileID: 742329082} - component: {fileID: 742329083} + - component: {fileID: 742329084} + - component: {fileID: 742329085} + - component: {fileID: 742329086} m_Layer: 0 m_Name: Player Spawner m_TagString: PlayerSpawner @@ -1212,12 +1215,49 @@ MonoBehaviour: playerPrefab: {fileID: 2029869654} playerList: - {fileID: 2029869654} +--- !u!114 &742329084 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 742329079} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 285df824d2011f6418a6a61acaee06c8, type: 3} + m_Name: + m_EditorClassIdentifier: playerSpeed: 5 - audioSource: {fileID: 275367939} - gateClip: {fileID: 8300000, guid: bc73c26acd33db94d9b0364cf657da1f, type: 3} - congratesClip: {fileID: 8300000, guid: d796b71420eabd14c90c84f26eb34f32, type: 3} - failClip: {fileID: 8300000, guid: 2524766b1871cd14abe8f46f4906557e, type: 3} - shootClip: {fileID: 8300000, guid: b3cc748c8e56877468096028fe00047b, type: 3} + isPlayerRunning: 0 +--- !u!114 &742329085 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 742329079} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fa3e94bee9b685b4091c92c50058825c, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &742329086 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 742329079} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3150a1b32e967d141ae9aac5c4ddbfca, type: 3} + m_Name: + m_EditorClassIdentifier: + audioSource: {fileID: 0} + gateClip: {fileID: 0} + congratesClip: {fileID: 0} + failClip: {fileID: 0} + shootClip: {fileID: 0} --- !u!1 &881636661 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 3afa141..eabb345 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -40,8 +40,8 @@ void Awake() public void StartGame() { menuPanel.SetActive(false); - SpawnPlayer spawnPlayer = GameObject.Find("Player Spawner").GetComponent(); - spawnPlayer.MovePlayer(); + PlayerMovement playerMovement = GameObject.Find("Player Spawner").GetComponent(); + playerMovement.MovePlayer(); } // Method to restart the game diff --git a/Assets/Scripts/Player/PlayerAudio.cs b/Assets/Scripts/Player/PlayerAudio.cs new file mode 100644 index 0000000..899e20c --- /dev/null +++ b/Assets/Scripts/Player/PlayerAudio.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerAudio : MonoBehaviour +{ + public AudioSource audioSource; + public AudioClip gateClip, congratesClip, failClip, shootClip; + + public void PlayCongratesSound() + { + PlayAudio(congratesClip); + StopBackgroundMusic(); + } + + public void PlayFailSound() + { + PlayAudio(failClip); + StopBackgroundMusic(); + } + + public void PlayGateSound() + { + PlayAudio(gateClip); + } + + public void PlayShootingSound() + { + PlayAudio(shootClip); + } + + public void PlayAudio(AudioClip clip) + { + if (audioSource != null) + { + audioSource.PlayOneShot(clip, 0.5f); + } + } + private void StopBackgroundMusic() + { + Camera.main.GetComponent().Stop(); + } +} diff --git a/Assets/Scripts/Player/PlayerAudio.cs.meta b/Assets/Scripts/Player/PlayerAudio.cs.meta new file mode 100644 index 0000000..24591ab --- /dev/null +++ b/Assets/Scripts/Player/PlayerAudio.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3150a1b32e967d141ae9aac5c4ddbfca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index 57b1378..046febc 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -1,7 +1,6 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using static UnityEngine.GraphicsBuffer; public class PlayerMovement : MonoBehaviour { @@ -10,24 +9,24 @@ public class PlayerMovement : MonoBehaviour float xSpeed; // Specify the maximum position on the X-axis float maxPosition = 4.10f; - - bool isPlayerRunning; + SpawnPlayer spawnPlayer; + public bool isPlayerRunning; // Start is called before the first frame update void Start() { - + spawnPlayer = GetComponent(); } // Update is called once per frame void Update() { - if (isPlayerRunning) + if (isPlayerRunning == false) { return; } - PlayerMovements(); + Movements(); } - void PlayerMovements() + void Movements() { // Variable to store the horizontal touch/mouse input float touchX = 0; @@ -61,22 +60,27 @@ private void OnTriggerEnter(Collider other) { if (other.tag == "Finish") { - isPlayerRunning = true; + isPlayerRunning = false; } } - public void EnemyDetected(GameObject enemy) + public void StopPlayer() { isPlayerRunning = false; } - private void LookAtEnemy(GameObject enemy) + public void MovePlayer() { - Vector3 direction = enemy.transform.position - transform.position ; - Quaternion lookAt = Quaternion.LookRotation(direction); - lookAt.x = 0; - lookAt.z = 0; - - transform.rotation = lookAt; + isPlayerRunning = true; + StartRunning(); } + private void StartRunning() + { + for (int i = 0; i < spawnPlayer.playerList.Count; i++) + { + PlayerController cop = spawnPlayer.playerList[i].GetComponent(); + cop.StartRunning(); + } + } + } diff --git a/Assets/Scripts/Player/PlayerRotation.cs b/Assets/Scripts/Player/PlayerRotation.cs new file mode 100644 index 0000000..88805a3 --- /dev/null +++ b/Assets/Scripts/Player/PlayerRotation.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerRotation : MonoBehaviour +{ + public void LookAtEnemy(GameObject enemy) + { + Vector3 direction = enemy.transform.position - transform.position; + Quaternion lookAt = Quaternion.LookRotation(direction); + lookAt.x = 0; + lookAt.z = 0; + + transform.rotation = lookAt; + } + public void LookForward() + { + transform.rotation = Quaternion.identity; + } +} diff --git a/Assets/Scripts/Player/PlayerRotation.cs.meta b/Assets/Scripts/Player/PlayerRotation.cs.meta new file mode 100644 index 0000000..b1e5649 --- /dev/null +++ b/Assets/Scripts/Player/PlayerRotation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fa3e94bee9b685b4091c92c50058825c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/SpawnPlayer.cs b/Assets/Scripts/Player/SpawnPlayer.cs index 292935b..c109e6b 100644 --- a/Assets/Scripts/Player/SpawnPlayer.cs +++ b/Assets/Scripts/Player/SpawnPlayer.cs @@ -5,91 +5,42 @@ public class SpawnPlayer : MonoBehaviour { [SerializeField] GameObject playerPrefab; - [SerializeField] List playerList; - [SerializeField] float playerSpeed = 5f; - // Variable to control the speed of player movement - float xSpeed; - // Specify the maximum position on the X-axis - float maxPosition = 4.10f; - public AudioSource audioSource; - public AudioClip gateClip, congratesClip, failClip, shootClip; - bool isPlayerRunning; + public List playerList; + + // Scripts + PlayerMovement playerMovement; + PlayerRotation playerRotation; + PlayerAudio playerAudio; + // Start is called before the first frame update void Start() { - isPlayerRunning = true; - } - // Update is called once per frame - void Update() - { - if (isPlayerRunning) - { - return; - } - PlayerMovements(); - } - - void PlayerMovements() - { - // Variable to store the horizontal touch/mouse input - float touchX = 0; - // Variable to store the resulting horizontal movement - float movementOnX = 0; - if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) - { - // Set the horizontal movement speed - xSpeed = 250; - // Get the horizontal delta position of the touch input - touchX = Input.GetTouch(0).deltaPosition.x / Screen.width; - } - else if (Input.GetMouseButton(0)) - { - // Set the horizontal movement speed - xSpeed = 500; - // Get the horizontal input axis of the mouse - touchX = Input.GetAxis("Mouse X"); - } - // Calculate the resulting horizontal movement - movementOnX = transform.position.x + xSpeed * touchX * Time.deltaTime; - // Clamp the resulting movement within the maximum position range - movementOnX = Mathf.Clamp(movementOnX, -maxPosition, maxPosition); - // Calculate the player's movement along the X-axis based on touch input or mouse input - Vector3 playerMovement = new Vector3(movementOnX, transform.position.y, transform.position.z + Time.deltaTime * playerSpeed); - // Apply the calculated movement to the player's position - transform.position = playerMovement; + playerMovement = GetComponent(); + playerRotation = GetComponent(); + playerAudio = GetComponent(); } private void OnTriggerEnter(Collider other) { if (other.tag == "Finish") { - isPlayerRunning = true; + playerMovement.StopPlayer(); GameManager.Instance.ShowWinPanel(); - PlayAudio(congratesClip); - StopBackgroundMusic(); + playerAudio.PlayCongratesSound(); } } public void EnemyDetected(GameObject enemy) { - isPlayerRunning = true; - LookAtEnemy(enemy); + playerMovement.StopPlayer(); + playerRotation.LookAtEnemy(enemy); StartShooting(); } - private void LookAtEnemy(GameObject enemy) - { - Vector3 direction = enemy.transform.position - transform.position; - Quaternion lookAt = Quaternion.LookRotation(direction); - lookAt.x = 0; - lookAt.z = 0; - - transform.rotation = lookAt; - } public void Spawn(int gateValue,GateType gateType) { - PlayAudio(gateClip); + playerAudio.PlayGateSound(); if (gateType == GateType.ADDITION) { for (int i = 0; i < gateValue; i++) @@ -121,44 +72,28 @@ public void KillCop(GameObject cop) public void AllZomibesKilled() { - LookForward(); - MovePlayer(); + playerRotation.LookForward(); + playerMovement.MovePlayer(); } private void DetectCopCount() { if (playerList.Count <= 0) { - StopPlayer(); + playerMovement.StopPlayer(); GameManager.Instance.ShowFailPanel(); - PlayAudio(failClip); - StopBackgroundMusic(); + playerAudio.PlayFailSound(); + } } - private void StopPlayer() - { - isPlayerRunning = true; - } - - public void MovePlayer() - { - isPlayerRunning = false; - StartRunning(); - } - - private void LookForward() - { - transform.rotation = Quaternion.identity; - } - private void StartShooting() { for(int i = 0;i < playerList.Count;i++) { PlayerController cop = playerList[i].GetComponent(); cop.StartShooting(); - PlayAudio(shootClip); + playerAudio.PlayShootingSound(); } } private void StartRunning() @@ -176,16 +111,4 @@ public Vector3 GetPlayerPosition() Vector3 newPosition = position + transform.position; return newPosition; } - - public void PlayAudio(AudioClip clip) - { - if(audioSource != null) - { - audioSource.PlayOneShot(clip,0.5f); - } - } - private void StopBackgroundMusic() - { - Camera.main.GetComponent().Stop(); - } } diff --git a/Assets/Scripts/Zombie/ZombieSpawner.cs b/Assets/Scripts/Zombie/ZombieSpawner.cs index 6c0194c..cd39bcc 100644 --- a/Assets/Scripts/Zombie/ZombieSpawner.cs +++ b/Assets/Scripts/Zombie/ZombieSpawner.cs @@ -15,7 +15,7 @@ private void Awake() } void Start() { - Spawn(3); + Spawn(8); } public void Spawn(int zombies) { From 617fc0605fe49b9d48bd1f569305e0554dfd98c8 Mon Sep 17 00:00:00 2001 From: hab Date: Fri, 14 Apr 2023 15:11:46 +0200 Subject: [PATCH 2/4] Cop Scripts & Audio Script --- Assets/Prefabs/{Police.prefab => Cop.prefab} | 43 +++- .../{Police.prefab.meta => Cop.prefab.meta} | 0 Assets/Scenes/GameScene.unity | 225 ++++++++++-------- Assets/Scripts/Cop.meta | 8 + Assets/Scripts/Cop/CopAnimation.cs | 25 ++ Assets/Scripts/Cop/CopAnimation.cs.meta | 11 + Assets/Scripts/Cop/CopBullets.cs | 26 ++ Assets/Scripts/Cop/CopBullets.cs.meta | 11 + Assets/Scripts/Cop/CopCenterized.cs | 19 ++ Assets/Scripts/Cop/CopCenterized.cs.meta | 11 + Assets/Scripts/Cop/CopController.cs | 28 +++ .../CopController.cs.meta} | 0 Assets/Scripts/Gate/GateController.cs | 7 +- Assets/Scripts/Player/PlayerController.cs | 62 ----- Assets/Scripts/Player/PlayerMovement.cs | 2 +- Assets/Scripts/Player/PlayerSpawning.cs | 54 +++++ Assets/Scripts/Player/PlayerSpawning.cs.meta | 11 + Assets/Scripts/Player/SpawnPlayer.cs | 16 +- .../AudioController.cs} | 6 +- .../AudioController.cs.meta} | 0 Assets/Scripts/Zombie/ZombieSpawner.cs | 2 +- 21 files changed, 383 insertions(+), 184 deletions(-) rename Assets/Prefabs/{Police.prefab => Cop.prefab} (96%) rename Assets/Prefabs/{Police.prefab.meta => Cop.prefab.meta} (100%) create mode 100644 Assets/Scripts/Cop.meta create mode 100644 Assets/Scripts/Cop/CopAnimation.cs create mode 100644 Assets/Scripts/Cop/CopAnimation.cs.meta create mode 100644 Assets/Scripts/Cop/CopBullets.cs create mode 100644 Assets/Scripts/Cop/CopBullets.cs.meta create mode 100644 Assets/Scripts/Cop/CopCenterized.cs create mode 100644 Assets/Scripts/Cop/CopCenterized.cs.meta create mode 100644 Assets/Scripts/Cop/CopController.cs rename Assets/Scripts/{Player/PlayerController.cs.meta => Cop/CopController.cs.meta} (100%) delete mode 100644 Assets/Scripts/Player/PlayerController.cs create mode 100644 Assets/Scripts/Player/PlayerSpawning.cs create mode 100644 Assets/Scripts/Player/PlayerSpawning.cs.meta rename Assets/Scripts/{Player/PlayerAudio.cs => Utils/AudioController.cs} (84%) rename Assets/Scripts/{Player/PlayerAudio.cs.meta => Utils/AudioController.cs.meta} (100%) diff --git a/Assets/Prefabs/Police.prefab b/Assets/Prefabs/Cop.prefab similarity index 96% rename from Assets/Prefabs/Police.prefab rename to Assets/Prefabs/Cop.prefab index f421215..74ca10e 100644 --- a/Assets/Prefabs/Police.prefab +++ b/Assets/Prefabs/Cop.prefab @@ -159,8 +159,11 @@ GameObject: - component: {fileID: 2029869656} - component: {fileID: 2029869655} - component: {fileID: 2029869662} + - component: {fileID: 8706587534195932413} + - component: {fileID: 2029869664} + - component: {fileID: 2029869665} m_Layer: 0 - m_Name: Police + m_Name: Cop m_TagString: Player m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -247,8 +250,46 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0a9885324a079f84c9062afea342983d, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &8706587534195932413 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8619338778009079851} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bf4133c59ea42bb41a06278bd0040cc4, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &2029869664 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8619338778009079851} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: eadfcd4e5aaab4f4186be237ae6f4367, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &2029869665 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8619338778009079851} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d06b65ffac4aeee44b540afdee5f4e98, type: 3} + m_Name: + m_EditorClassIdentifier: bullet: {fileID: 5689450973616959451, guid: a5b944ff0c1dd9b40a3a1c4365dd2ce1, type: 3} bulletTransform: {fileID: 8900475362468441194} + bulletSpeed: 10 + isShootingOn: 0 --- !u!1 &8619338778009079855 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Police.prefab.meta b/Assets/Prefabs/Cop.prefab.meta similarity index 100% rename from Assets/Prefabs/Police.prefab.meta rename to Assets/Prefabs/Cop.prefab.meta diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 6323ec3..1cc16b2 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -219,6 +219,8 @@ GameObject: m_Component: - component: {fileID: 275367938} - component: {fileID: 275367939} + - component: {fileID: 275367940} + - component: {fileID: 275367941} m_Layer: 0 m_Name: AudioSource m_TagString: Untagged @@ -337,6 +339,120 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &275367940 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 275367937} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3150a1b32e967d141ae9aac5c4ddbfca, type: 3} + m_Name: + m_EditorClassIdentifier: + audioSource: {fileID: 275367939} + backgroundAudio: {fileID: 275367941} + gateClip: {fileID: 8300000, guid: bc73c26acd33db94d9b0364cf657da1f, type: 3} + congratesClip: {fileID: 8300000, guid: d796b71420eabd14c90c84f26eb34f32, type: 3} + failClip: {fileID: 8300000, guid: 2524766b1871cd14abe8f46f4906557e, type: 3} + shootClip: {fileID: 8300000, guid: b3cc748c8e56877468096028fe00047b, type: 3} +--- !u!82 &275367941 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 275367937} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 8300000, guid: ca907e894957c5f48b7f2f77f784dd18, type: 3} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 1 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &286861847 GameObject: m_ObjectHideFlags: 0 @@ -1250,14 +1366,12 @@ MonoBehaviour: m_GameObject: {fileID: 742329079} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3150a1b32e967d141ae9aac5c4ddbfca, type: 3} + m_Script: {fileID: 11500000, guid: f5848ccac48702f4da7cd082ce29ff8b, type: 3} m_Name: m_EditorClassIdentifier: - audioSource: {fileID: 0} - gateClip: {fileID: 0} - congratesClip: {fileID: 0} - failClip: {fileID: 0} - shootClip: {fileID: 0} + copPrefab: {fileID: 2029869654} + copList: + - {fileID: 2029869654} --- !u!1 &881636661 GameObject: m_ObjectHideFlags: 0 @@ -1403,7 +1517,6 @@ GameObject: - component: {fileID: 963194227} - component: {fileID: 963194226} - component: {fileID: 963194229} - - component: {fileID: 963194230} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -1491,102 +1604,6 @@ MonoBehaviour: m_EditorClassIdentifier: player: {fileID: 742329080} offset: {x: 5.69, y: 11.23, z: -10.93} ---- !u!82 &963194230 -AudioSource: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 963194225} - m_Enabled: 1 - serializedVersion: 4 - OutputAudioMixerGroup: {fileID: 0} - m_audioClip: {fileID: 8300000, guid: ca907e894957c5f48b7f2f77f784dd18, type: 3} - m_PlayOnAwake: 1 - m_Volume: 1 - m_Pitch: 1 - Loop: 1 - Mute: 0 - Spatialize: 0 - SpatializePostEffects: 0 - Priority: 128 - DopplerLevel: 1 - MinDistance: 1 - MaxDistance: 500 - Pan2D: 0 - rolloffMode: 0 - BypassEffects: 0 - BypassListenerEffects: 0 - BypassReverbZones: 0 - rolloffCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - panLevelCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - spreadCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - reverbZoneMixCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 --- !u!1 &963637484 GameObject: m_ObjectHideFlags: 0 @@ -2245,7 +2262,7 @@ PrefabInstance: m_Modifications: - target: {fileID: 8619338778009079851, guid: 47a3741b253f088469eedd6d403dd89a, type: 3} propertyPath: m_Name - value: Player + value: Cop objectReference: {fileID: 0} - target: {fileID: 8619338778009177163, guid: 47a3741b253f088469eedd6d403dd89a, type: 3} propertyPath: m_RootOrder diff --git a/Assets/Scripts/Cop.meta b/Assets/Scripts/Cop.meta new file mode 100644 index 0000000..df2ff1e --- /dev/null +++ b/Assets/Scripts/Cop.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 132bf23462bf64f45b3cbb1bd87a7ed9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Cop/CopAnimation.cs b/Assets/Scripts/Cop/CopAnimation.cs new file mode 100644 index 0000000..330e966 --- /dev/null +++ b/Assets/Scripts/Cop/CopAnimation.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CopAnimation : MonoBehaviour +{ + private Animator animator; + // Start is called before the first frame update + void Start() + { + animator = GetComponent(); + } + + public void StartRunningAnim() + { + animator.SetBool("isShooting", false); + animator.SetBool("isRunning", true); + } + + public void StartShootingAnim() + { + animator.SetBool("isRunning", false); + animator.SetBool("isShooting", true); + } +} diff --git a/Assets/Scripts/Cop/CopAnimation.cs.meta b/Assets/Scripts/Cop/CopAnimation.cs.meta new file mode 100644 index 0000000..c21955d --- /dev/null +++ b/Assets/Scripts/Cop/CopAnimation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eadfcd4e5aaab4f4186be237ae6f4367 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Cop/CopBullets.cs b/Assets/Scripts/Cop/CopBullets.cs new file mode 100644 index 0000000..1e50943 --- /dev/null +++ b/Assets/Scripts/Cop/CopBullets.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CopBullets : MonoBehaviour +{ + public GameObject bullet; + public Transform bulletTransform; + public int bulletSpeed = 10; + public bool isShootingOn = false; + + public IEnumerator Shooting() + { + while (isShootingOn) + { + Shoot(); + yield return new WaitForSeconds(1f); + } + } + private void Shoot() + { + GameObject bulletInstance = Instantiate(bullet, bulletTransform.position, Quaternion.identity); + Rigidbody rigidbody = bulletInstance.GetComponent(); + rigidbody.velocity = transform.forward * bulletSpeed; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Cop/CopBullets.cs.meta b/Assets/Scripts/Cop/CopBullets.cs.meta new file mode 100644 index 0000000..e74dbf8 --- /dev/null +++ b/Assets/Scripts/Cop/CopBullets.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d06b65ffac4aeee44b540afdee5f4e98 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Cop/CopCenterized.cs b/Assets/Scripts/Cop/CopCenterized.cs new file mode 100644 index 0000000..0e4dd3d --- /dev/null +++ b/Assets/Scripts/Cop/CopCenterized.cs @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CopCenterized : MonoBehaviour +{ + private Transform playerSpawnerCenter; + private float goToCenter = 5f; + // Start is called before the first frame update + void Start() + { + playerSpawnerCenter = transform.parent.gameObject.transform; + } + + private void FixedUpdate() + { + transform.position = Vector3.MoveTowards(transform.position, playerSpawnerCenter.position, Time.fixedDeltaTime * goToCenter); + } +} diff --git a/Assets/Scripts/Cop/CopCenterized.cs.meta b/Assets/Scripts/Cop/CopCenterized.cs.meta new file mode 100644 index 0000000..42ad9d9 --- /dev/null +++ b/Assets/Scripts/Cop/CopCenterized.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bf4133c59ea42bb41a06278bd0040cc4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Cop/CopController.cs b/Assets/Scripts/Cop/CopController.cs new file mode 100644 index 0000000..435e0be --- /dev/null +++ b/Assets/Scripts/Cop/CopController.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CopController : MonoBehaviour +{ + + private CopAnimation copAnimation; + private CopBullets copBullets; + + private void Awake() + { + copAnimation = GetComponent(); + copBullets = GetComponent(); + } + + public void StartShooting() + { + copBullets.isShootingOn = true; + StartCoroutine(copBullets.Shooting()); + copAnimation.StartShootingAnim(); + } + public void StartRunning() + { + copBullets.isShootingOn = false; + copAnimation.StartRunningAnim(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerController.cs.meta b/Assets/Scripts/Cop/CopController.cs.meta similarity index 100% rename from Assets/Scripts/Player/PlayerController.cs.meta rename to Assets/Scripts/Cop/CopController.cs.meta diff --git a/Assets/Scripts/Gate/GateController.cs b/Assets/Scripts/Gate/GateController.cs index bd3a3c1..92e4632 100644 --- a/Assets/Scripts/Gate/GateController.cs +++ b/Assets/Scripts/Gate/GateController.cs @@ -9,6 +9,7 @@ public class GateController : MonoBehaviour { bool isPlayerTouchGate = true; SpawnPlayer spawnPlayer; + PlayerSpawning playerSpawning; GateHolderController gateController; int gateValue; public GateType gateType; @@ -18,6 +19,7 @@ void Start() { gateValue = 5; spawnPlayer = GameObject.FindGameObjectWithTag("PlayerSpawner").GetComponent(); + playerSpawning = GameObject.FindGameObjectWithTag("PlayerSpawner").GetComponent(); gateController = transform.parent.gameObject.GetComponent(); UpdateText(); } @@ -26,11 +28,8 @@ private void OnTriggerEnter(Collider other) if ( other.tag == "Player" && isPlayerTouchGate) { isPlayerTouchGate = false; - Debug.Log("Close The Gate"); gateController.CloseGate(); - Debug.Log("Spawn Players"); - spawnPlayer.Spawn(gateValue, gateType); - Debug.Log("Destroy"); + playerSpawning.Spawn(gateValue, gateType); Destroy(this.gameObject); } } diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs deleted file mode 100644 index ce2c89f..0000000 --- a/Assets/Scripts/Player/PlayerController.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class PlayerController : MonoBehaviour -{ - Animator animator; - public GameObject bullet; - public Transform bulletTransform; - private Transform playerSpawnerCenter; - int bulletSpeed = 10; - float goToCenter = 5f; - bool isShootingOn = false; - - private void Awake() - { - animator = GetComponent(); - playerSpawnerCenter = transform.parent.gameObject.transform; - } - private void FixedUpdate() - { - transform.position = Vector3.MoveTowards(transform.position, playerSpawnerCenter.position, Time.fixedDeltaTime * goToCenter) ; - } - - public void StartShooting() - { - isShootingOn = true; - StartCoroutine(Shooting()); - StartShootingAnim(); - } - public void StartRunning() - { - isShootingOn = false; - StartRunningAnim(); - } - IEnumerator Shooting() - { - while (isShootingOn) - { - Shoot(); - yield return new WaitForSeconds(1f); - } - } - private void Shoot() - { - GameObject bulletInstance = Instantiate(bullet,bulletTransform.position,Quaternion.identity); - Rigidbody rigidbody = bulletInstance.GetComponent(); - rigidbody.velocity = transform.forward * bulletSpeed; - } - - public void StartRunningAnim() - { - animator.SetBool("isShooting", false); - animator.SetBool("isRunning", true); - } - - public void StartShootingAnim() - { - animator.SetBool("isRunning", false); - animator.SetBool("isShooting", true); - } -} diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index 046febc..18cdc0c 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -78,7 +78,7 @@ private void StartRunning() { for (int i = 0; i < spawnPlayer.playerList.Count; i++) { - PlayerController cop = spawnPlayer.playerList[i].GetComponent(); + CopController cop = spawnPlayer.playerList[i].GetComponent(); cop.StartRunning(); } } diff --git a/Assets/Scripts/Player/PlayerSpawning.cs b/Assets/Scripts/Player/PlayerSpawning.cs new file mode 100644 index 0000000..0bdf942 --- /dev/null +++ b/Assets/Scripts/Player/PlayerSpawning.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerSpawning : MonoBehaviour +{ + private static PlayerSpawning _instance; // private static instance field + public static PlayerSpawning Instance { get { return _instance; } } // public static instance property + + [SerializeField] GameObject copPrefab; + public List copList; + + private void Awake() + { + // Ensure only one instance of the class is created + if (_instance != null && _instance != this) + { + Destroy(this.gameObject); + return; + } + _instance = this; + } + + public void Spawn(int gateValue, GateType gateType) + { + //audioController.PlayGateSound(); + if (gateType == GateType.ADDITION) + { + for (int i = 0; i < gateValue; i++) + { + // Instantiate the player prefab at the specified spawn position + GameObject playerInstance = Instantiate(copPrefab, GetPlayerPosition(), Quaternion.identity, transform); + copList.Add(playerInstance); + } + } + else if (gateType == GateType.MULTIPLY) + { + int playerCount = (copList.Count * gateValue) - copList.Count; + for (int i = 0; i < playerCount; i++) + { + // Instantiate the player prefab at the specified spawn position + GameObject playerInstance = Instantiate(copPrefab, GetPlayerPosition(), Quaternion.identity, transform); + copList.Add(playerInstance); + } + } + + } + private Vector3 GetPlayerPosition() + { + Vector3 position = Random.insideUnitSphere * 0.1f; + Vector3 newPosition = position + transform.position; + return newPosition; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerSpawning.cs.meta b/Assets/Scripts/Player/PlayerSpawning.cs.meta new file mode 100644 index 0000000..dc56803 --- /dev/null +++ b/Assets/Scripts/Player/PlayerSpawning.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f5848ccac48702f4da7cd082ce29ff8b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/SpawnPlayer.cs b/Assets/Scripts/Player/SpawnPlayer.cs index c109e6b..810c11c 100644 --- a/Assets/Scripts/Player/SpawnPlayer.cs +++ b/Assets/Scripts/Player/SpawnPlayer.cs @@ -10,14 +10,14 @@ public class SpawnPlayer : MonoBehaviour // Scripts PlayerMovement playerMovement; PlayerRotation playerRotation; - PlayerAudio playerAudio; + AudioController audioController; // Start is called before the first frame update void Start() { playerMovement = GetComponent(); playerRotation = GetComponent(); - playerAudio = GetComponent(); + audioController = GameObject.Find("AudioSource").GetComponent(); } private void OnTriggerEnter(Collider other) @@ -26,7 +26,7 @@ private void OnTriggerEnter(Collider other) { playerMovement.StopPlayer(); GameManager.Instance.ShowWinPanel(); - playerAudio.PlayCongratesSound(); + audioController.PlayCongratesSound(); } } @@ -40,7 +40,7 @@ public void EnemyDetected(GameObject enemy) public void Spawn(int gateValue,GateType gateType) { - playerAudio.PlayGateSound(); + audioController.PlayGateSound(); if (gateType == GateType.ADDITION) { for (int i = 0; i < gateValue; i++) @@ -82,7 +82,7 @@ private void DetectCopCount() { playerMovement.StopPlayer(); GameManager.Instance.ShowFailPanel(); - playerAudio.PlayFailSound(); + audioController.PlayFailSound(); } } @@ -91,16 +91,16 @@ private void StartShooting() { for(int i = 0;i < playerList.Count;i++) { - PlayerController cop = playerList[i].GetComponent(); + CopController cop = playerList[i].GetComponent(); cop.StartShooting(); - playerAudio.PlayShootingSound(); + audioController.PlayShootingSound(); } } private void StartRunning() { for (int i = 0; i < playerList.Count; i++) { - PlayerController cop = playerList[i].GetComponent(); + CopController cop = playerList[i].GetComponent(); cop.StartRunning(); } } diff --git a/Assets/Scripts/Player/PlayerAudio.cs b/Assets/Scripts/Utils/AudioController.cs similarity index 84% rename from Assets/Scripts/Player/PlayerAudio.cs rename to Assets/Scripts/Utils/AudioController.cs index 899e20c..d3eba5c 100644 --- a/Assets/Scripts/Player/PlayerAudio.cs +++ b/Assets/Scripts/Utils/AudioController.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using UnityEngine; -public class PlayerAudio : MonoBehaviour +public class AudioController : MonoBehaviour { - public AudioSource audioSource; + public AudioSource audioSource,backgroundAudio; public AudioClip gateClip, congratesClip, failClip, shootClip; public void PlayCongratesSound() @@ -38,6 +38,6 @@ public void PlayAudio(AudioClip clip) } private void StopBackgroundMusic() { - Camera.main.GetComponent().Stop(); + backgroundAudio.Stop(); } } diff --git a/Assets/Scripts/Player/PlayerAudio.cs.meta b/Assets/Scripts/Utils/AudioController.cs.meta similarity index 100% rename from Assets/Scripts/Player/PlayerAudio.cs.meta rename to Assets/Scripts/Utils/AudioController.cs.meta diff --git a/Assets/Scripts/Zombie/ZombieSpawner.cs b/Assets/Scripts/Zombie/ZombieSpawner.cs index cd39bcc..e6d86de 100644 --- a/Assets/Scripts/Zombie/ZombieSpawner.cs +++ b/Assets/Scripts/Zombie/ZombieSpawner.cs @@ -15,7 +15,7 @@ private void Awake() } void Start() { - Spawn(8); + Spawn(18); } public void Spawn(int zombies) { From a872683b7aad7cb4c00e112a52eaaa395b24b53d Mon Sep 17 00:00:00 2001 From: hab Date: Sat, 15 Apr 2023 01:54:52 +0200 Subject: [PATCH 3/4] Basic Game Play --- Assets/Prefabs/Zombie.prefab | 14 +++ Assets/Scenes/GameScene.unity | 19 ++- Assets/Scripts/Gate/GateController.cs | 7 +- Assets/Scripts/Player/PlayerController.cs | 80 ++++++++++++ ...layer.cs.meta => PlayerController.cs.meta} | 0 Assets/Scripts/Player/PlayerMovement.cs | 26 +--- Assets/Scripts/Player/PlayerSpawning.cs | 30 ++--- Assets/Scripts/Player/SpawnPlayer.cs | 114 ------------------ Assets/Scripts/Utils/ObstacleController.cs | 6 +- .../Scripts/Zombie/EnemySpawnerController.cs | 59 +++++++++ .../Zombie/EnemySpawnerController.cs.meta | 11 ++ Assets/Scripts/Zombie/ZombieController.cs | 15 +-- Assets/Scripts/Zombie/ZombieMovement.cs | 17 +++ Assets/Scripts/Zombie/ZombieMovement.cs.meta | 11 ++ Assets/Scripts/Zombie/ZombieSpawner.cs | 60 +++------ 15 files changed, 250 insertions(+), 219 deletions(-) create mode 100644 Assets/Scripts/Player/PlayerController.cs rename Assets/Scripts/Player/{SpawnPlayer.cs.meta => PlayerController.cs.meta} (100%) delete mode 100644 Assets/Scripts/Player/SpawnPlayer.cs create mode 100644 Assets/Scripts/Zombie/EnemySpawnerController.cs create mode 100644 Assets/Scripts/Zombie/EnemySpawnerController.cs.meta create mode 100644 Assets/Scripts/Zombie/ZombieMovement.cs create mode 100644 Assets/Scripts/Zombie/ZombieMovement.cs.meta diff --git a/Assets/Prefabs/Zombie.prefab b/Assets/Prefabs/Zombie.prefab index 488d038..becac62 100644 --- a/Assets/Prefabs/Zombie.prefab +++ b/Assets/Prefabs/Zombie.prefab @@ -76,6 +76,7 @@ GameObject: - component: {fileID: 1552702606} - component: {fileID: 1552702605} - component: {fileID: 6136956654677822583} + - component: {fileID: -9185599043494665271} m_Layer: 0 m_Name: Zombie m_TagString: Untagged @@ -164,6 +165,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: player: {fileID: 0} + spawner: {fileID: 0} +--- !u!114 &-9185599043494665271 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 856601670117699726} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 068545d5f77a54647927a2a14a186013, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &856601670117699840 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 1cc16b2..283904c 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -464,8 +464,9 @@ GameObject: - component: {fileID: 286861848} - component: {fileID: 286861849} - component: {fileID: 286861850} + - component: {fileID: 286861851} m_Layer: 0 - m_Name: Zombie Spawner + m_Name: Enemy Spawner m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -500,6 +501,7 @@ MonoBehaviour: m_EditorClassIdentifier: zombiePrefab: {fileID: 856601670117699726, guid: b14953694d54eea4eb66f453e525024c, type: 3} zombieList: [] + enemysNumber: 5 isZombieAttack: 0 --- !u!65 &286861850 BoxCollider: @@ -514,6 +516,18 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 6.1, y: 0.5, z: 7.8093915} m_Center: {x: 0, y: 0, z: 0.40469575} +--- !u!114 &286861851 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 286861847} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e251059c5953f8249897732bc62da839, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &335817951 GameObject: m_ObjectHideFlags: 0 @@ -1328,9 +1342,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 871b9b2f18b18bb4bb1442bb1e27fe81, type: 3} m_Name: m_EditorClassIdentifier: - playerPrefab: {fileID: 2029869654} - playerList: - - {fileID: 2029869654} --- !u!114 &742329084 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Gate/GateController.cs b/Assets/Scripts/Gate/GateController.cs index 92e4632..6e5bbe6 100644 --- a/Assets/Scripts/Gate/GateController.cs +++ b/Assets/Scripts/Gate/GateController.cs @@ -8,18 +8,15 @@ public enum GateType { MULTIPLY, ADDITION }; public class GateController : MonoBehaviour { bool isPlayerTouchGate = true; - SpawnPlayer spawnPlayer; PlayerSpawning playerSpawning; GateHolderController gateController; - int gateValue; + public int gateValue = 2; public GateType gateType; public TextMeshProUGUI text; // Start is called before the first frame update void Start() { - gateValue = 5; - spawnPlayer = GameObject.FindGameObjectWithTag("PlayerSpawner").GetComponent(); - playerSpawning = GameObject.FindGameObjectWithTag("PlayerSpawner").GetComponent(); + playerSpawning = GameObject.Find("Player Spawner").GetComponent(); gateController = transform.parent.gameObject.GetComponent(); UpdateText(); } diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs new file mode 100644 index 0000000..c69fe3c --- /dev/null +++ b/Assets/Scripts/Player/PlayerController.cs @@ -0,0 +1,80 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; + +public class PlayerController : MonoBehaviour +{ + // Scripts + PlayerMovement playerMovement; + PlayerRotation playerRotation; + PlayerSpawning playerSpawning; + AudioController audioController; + + void Start() + { + playerMovement = GetComponent(); + playerRotation = GetComponent(); + playerSpawning = GetComponent(); + audioController = GameObject.Find("AudioSource").GetComponent(); + } + + private void OnTriggerEnter(Collider other) + { + if (other.tag == "Finish") + { + playerMovement.StopPlayer(); + GameManager.Instance.ShowWinPanel(); + audioController.PlayCongratesSound(); + } + } + + public void KillCop(GameObject cop) + { + playerSpawning.RemoveFromList(cop); + DetectCopCount(); + } + + private void DetectCopCount() + { + if (playerSpawning.CopsNumber() <= 0) + { + playerMovement.StopPlayer(); + GameManager.Instance.ShowFailPanel(); + audioController.PlayFailSound(); + } + } + + public void EnemyDetected(GameObject enemy) + { + playerMovement.StopPlayer(); + playerRotation.LookAtEnemy(enemy); + StartShooting(); + } + + public void AllZomibesKilled() + { + playerRotation.LookForward(); + playerMovement.MovePlayer(); + StartRunning(); + } + + private void StartShooting() + { + for(int i = 0;i < playerSpawning.CopsNumber();i++) + { + CopController cop = playerSpawning.getCop(i).GetComponent(); + cop.StartShooting(); + audioController.PlayShootingSound(); + } + } + + private void StartRunning() + { + for (int i = 0; i < playerSpawning.CopsNumber(); i++) + { + CopController cop = playerSpawning.getCop(i).GetComponent(); + cop.StartRunning(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Player/SpawnPlayer.cs.meta b/Assets/Scripts/Player/PlayerController.cs.meta similarity index 100% rename from Assets/Scripts/Player/SpawnPlayer.cs.meta rename to Assets/Scripts/Player/PlayerController.cs.meta diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index 18cdc0c..3daf73a 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -9,14 +9,8 @@ public class PlayerMovement : MonoBehaviour float xSpeed; // Specify the maximum position on the X-axis float maxPosition = 4.10f; - SpawnPlayer spawnPlayer; public bool isPlayerRunning; - // Start is called before the first frame update - void Start() - { - spawnPlayer = GetComponent(); - } - // Update is called once per frame + void Update() { if (isPlayerRunning == false) @@ -56,14 +50,6 @@ void Movements() transform.position = playerMovement; } - private void OnTriggerEnter(Collider other) - { - if (other.tag == "Finish") - { - isPlayerRunning = false; - } - } - public void StopPlayer() { isPlayerRunning = false; @@ -72,15 +58,5 @@ public void StopPlayer() public void MovePlayer() { isPlayerRunning = true; - StartRunning(); - } - private void StartRunning() - { - for (int i = 0; i < spawnPlayer.playerList.Count; i++) - { - CopController cop = spawnPlayer.playerList[i].GetComponent(); - cop.StartRunning(); - } } - } diff --git a/Assets/Scripts/Player/PlayerSpawning.cs b/Assets/Scripts/Player/PlayerSpawning.cs index 0bdf942..c4fd9b5 100644 --- a/Assets/Scripts/Player/PlayerSpawning.cs +++ b/Assets/Scripts/Player/PlayerSpawning.cs @@ -4,23 +4,9 @@ public class PlayerSpawning : MonoBehaviour { - private static PlayerSpawning _instance; // private static instance field - public static PlayerSpawning Instance { get { return _instance; } } // public static instance property - [SerializeField] GameObject copPrefab; public List copList; - private void Awake() - { - // Ensure only one instance of the class is created - if (_instance != null && _instance != this) - { - Destroy(this.gameObject); - return; - } - _instance = this; - } - public void Spawn(int gateValue, GateType gateType) { //audioController.PlayGateSound(); @@ -51,4 +37,20 @@ private Vector3 GetPlayerPosition() Vector3 newPosition = position + transform.position; return newPosition; } + + public void RemoveFromList(GameObject cop) + { + copList.Remove(cop); + Destroy(cop); + } + + public int CopsNumber() + { + return copList.Count; + } + + public GameObject getCop(int i) + { + return copList[i]; + } } \ No newline at end of file diff --git a/Assets/Scripts/Player/SpawnPlayer.cs b/Assets/Scripts/Player/SpawnPlayer.cs deleted file mode 100644 index 810c11c..0000000 --- a/Assets/Scripts/Player/SpawnPlayer.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class SpawnPlayer : MonoBehaviour -{ - [SerializeField] GameObject playerPrefab; - public List playerList; - - // Scripts - PlayerMovement playerMovement; - PlayerRotation playerRotation; - AudioController audioController; - - // Start is called before the first frame update - void Start() - { - playerMovement = GetComponent(); - playerRotation = GetComponent(); - audioController = GameObject.Find("AudioSource").GetComponent(); - } - - private void OnTriggerEnter(Collider other) - { - if (other.tag == "Finish") - { - playerMovement.StopPlayer(); - GameManager.Instance.ShowWinPanel(); - audioController.PlayCongratesSound(); - } - } - - public void EnemyDetected(GameObject enemy) - { - playerMovement.StopPlayer(); - playerRotation.LookAtEnemy(enemy); - StartShooting(); - } - - - public void Spawn(int gateValue,GateType gateType) - { - audioController.PlayGateSound(); - if (gateType == GateType.ADDITION) - { - for (int i = 0; i < gateValue; i++) - { - // Instantiate the player prefab at the specified spawn position - GameObject playerInstance = Instantiate(playerPrefab, GetPlayerPosition(), Quaternion.identity, transform); - playerList.Add(playerInstance); - } - } - else if(gateType == GateType.MULTIPLY) - { - int playerCount = (playerList.Count * gateValue) - playerList.Count; - for (int i = 0; i < playerCount; i++) - { - // Instantiate the player prefab at the specified spawn position - GameObject playerInstance = Instantiate(playerPrefab, GetPlayerPosition(), Quaternion.identity, transform); - playerList.Add(playerInstance); - } - } - - } - - public void KillCop(GameObject cop) - { - playerList.Remove(cop); - Destroy(cop); - DetectCopCount(); - } - - public void AllZomibesKilled() - { - playerRotation.LookForward(); - playerMovement.MovePlayer(); - } - - private void DetectCopCount() - { - if (playerList.Count <= 0) - { - playerMovement.StopPlayer(); - GameManager.Instance.ShowFailPanel(); - audioController.PlayFailSound(); - - } - } - - private void StartShooting() - { - for(int i = 0;i < playerList.Count;i++) - { - CopController cop = playerList[i].GetComponent(); - cop.StartShooting(); - audioController.PlayShootingSound(); - } - } - private void StartRunning() - { - for (int i = 0; i < playerList.Count; i++) - { - CopController cop = playerList[i].GetComponent(); - cop.StartRunning(); - } - } - - public Vector3 GetPlayerPosition() - { - Vector3 position = Random.insideUnitSphere * 0.1f; - Vector3 newPosition = position + transform.position; - return newPosition; - } -} diff --git a/Assets/Scripts/Utils/ObstacleController.cs b/Assets/Scripts/Utils/ObstacleController.cs index 353a77c..683f9c5 100644 --- a/Assets/Scripts/Utils/ObstacleController.cs +++ b/Assets/Scripts/Utils/ObstacleController.cs @@ -4,18 +4,18 @@ public class ObstacleController : MonoBehaviour { - SpawnPlayer SpawnPlayer; + PlayerController playerController; // Start is called before the first frame update void Start() { - SpawnPlayer = GameObject.FindGameObjectWithTag("PlayerSpawner").GetComponent(); + playerController = GameObject.Find("Player Spawner").GetComponent(); } private void OnTriggerEnter(Collider other) { if (other.tag == "Player") { - SpawnPlayer.KillCop(other.gameObject); + playerController.KillCop(other.gameObject); } } } diff --git a/Assets/Scripts/Zombie/EnemySpawnerController.cs b/Assets/Scripts/Zombie/EnemySpawnerController.cs new file mode 100644 index 0000000..29a7dab --- /dev/null +++ b/Assets/Scripts/Zombie/EnemySpawnerController.cs @@ -0,0 +1,59 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EnemySpawnerController : MonoBehaviour +{ + ZombieSpawner zombieSpawner; + PlayerController playerController; + + private void Start() + { + zombieSpawner = GetComponent(); + playerController = GameObject.Find("Player Spawner").GetComponent(); + } + + private void OnTriggerEnter(Collider other) + { + if (other.tag == "Player") + { + zombieSpawner.isZombieAttack = true; + playerController.EnemyDetected(gameObject); + LookAtPlayer(other.gameObject); + GetComponent().enabled = false; + } + } + + private void LookAtPlayer(GameObject target) + { + // Calculate direction from this object's position to the player's position + Vector3 direction = target.transform.position - transform.position; + + // Calculate rotation to look at the direction + Quaternion lookAtRotation = Quaternion.LookRotation(direction); + + // Set rotation for this object + transform.rotation = lookAtRotation; + } + + public void ZombieAttackTheCops(GameObject cop, GameObject zombie) + { + zombieSpawner.RemoveFromList(zombie); + CheckZombieCount(); + playerController.KillCop(cop); + } + + public void ZombieGotShoot(GameObject zombie) + { + zombieSpawner.RemoveFromList(zombie); + CheckZombieCount(); + } + + private void CheckZombieCount() + { + if (zombieSpawner.ZombieNumber() <= 0) + { + playerController.AllZomibesKilled(); + } + } +} diff --git a/Assets/Scripts/Zombie/EnemySpawnerController.cs.meta b/Assets/Scripts/Zombie/EnemySpawnerController.cs.meta new file mode 100644 index 0000000..2837408 --- /dev/null +++ b/Assets/Scripts/Zombie/EnemySpawnerController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e251059c5953f8249897732bc62da839 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Zombie/ZombieController.cs b/Assets/Scripts/Zombie/ZombieController.cs index 50d7f14..da2860e 100644 --- a/Assets/Scripts/Zombie/ZombieController.cs +++ b/Assets/Scripts/Zombie/ZombieController.cs @@ -4,34 +4,27 @@ public class ZombieController : MonoBehaviour { - public SpawnPlayer player; - public ZombieSpawner spawner; + public EnemySpawnerController controller; bool isZombieAlive; // Start is called before the first frame update void Start() { isZombieAlive = true; } - private void FixedUpdate() - { - if (spawner.isZombieAttack) - { - transform.position = Vector3.MoveTowards(transform.position, player.transform.position, Time.fixedDeltaTime * 1.5f); - } - } + private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Player" && isZombieAlive == true) { isZombieAlive = false; - spawner.ZombieAttackTheCops(cop: collision.gameObject, zombie: gameObject); + controller.ZombieAttackTheCops(cop: collision.gameObject, zombie: gameObject); } } private void OnTriggerEnter(Collider other) { if (other.tag == "Bullet") { - spawner.ZombieGotShoot(gameObject); + controller.ZombieGotShoot(gameObject); Destroy(other.gameObject); } } diff --git a/Assets/Scripts/Zombie/ZombieMovement.cs b/Assets/Scripts/Zombie/ZombieMovement.cs new file mode 100644 index 0000000..3ff9e56 --- /dev/null +++ b/Assets/Scripts/Zombie/ZombieMovement.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ZombieMovement : MonoBehaviour +{ + public PlayerController player; + public ZombieSpawner spawner; + + private void FixedUpdate() + { + if (spawner.isZombieAttack) + { + transform.position = Vector3.MoveTowards(transform.position, player.transform.position, Time.fixedDeltaTime * 1.5f); + } + } +} diff --git a/Assets/Scripts/Zombie/ZombieMovement.cs.meta b/Assets/Scripts/Zombie/ZombieMovement.cs.meta new file mode 100644 index 0000000..fc886c0 --- /dev/null +++ b/Assets/Scripts/Zombie/ZombieMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 068545d5f77a54647927a2a14a186013 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Zombie/ZombieSpawner.cs b/Assets/Scripts/Zombie/ZombieSpawner.cs index e6d86de..21e7d9f 100644 --- a/Assets/Scripts/Zombie/ZombieSpawner.cs +++ b/Assets/Scripts/Zombie/ZombieSpawner.cs @@ -6,16 +6,19 @@ public class ZombieSpawner : MonoBehaviour { [SerializeField] GameObject zombiePrefab; [SerializeField] List zombieList; - SpawnPlayer spawnPlayer; + [SerializeField] int enemysNumber = 5; + PlayerController playerController; + EnemySpawnerController controller; public bool isZombieAttack; - // Start is called before the first frame update + private void Awake() { - spawnPlayer = GameObject.Find("Player Spawner").GetComponent(); + playerController = GameObject.Find("Player Spawner").GetComponent(); + controller = GetComponent(); } void Start() { - Spawn(18); + Spawn(enemysNumber); } public void Spawn(int zombies) { @@ -24,9 +27,11 @@ public void Spawn(int zombies) Quaternion zombieAngel = Quaternion.Euler(new Vector3(0, 180, 0)); // Instantiate the player prefab at the specified spawn position GameObject zomibeInstance = Instantiate(zombiePrefab, GetZombiePosition(), zombieAngel, transform); - ZombieController zombieController = zomibeInstance.GetComponent(); - zombieController.player = spawnPlayer; - zombieController.spawner = this; + ZombieMovement zombieMovement = zomibeInstance.GetComponent(); + ZombieController zombieController = zomibeInstance.GetComponent(); + zombieController.controller = controller; + zombieMovement.player = playerController; + zombieMovement.spawner = this; zombieList.Add(zomibeInstance); } } @@ -36,49 +41,18 @@ public Vector3 GetZombiePosition() Vector3 newPosition = position + transform.position; return newPosition; } - private void OnTriggerEnter(Collider other) - { - if(other.tag == "Player") - { - isZombieAttack = true; - spawnPlayer.EnemyDetected(gameObject); - LookAtPlayer(other.gameObject); - GetComponent().enabled = false; - } - } - private void LookAtPlayer(GameObject target) - { - // Calculate direction from this object's position to the player's position - Vector3 direction = target.transform.position - transform.position; - - // Calculate rotation to look at the direction - Quaternion lookAtRotation = Quaternion.LookRotation(direction); - - // Set rotation for this object - transform.rotation = lookAtRotation; - } - - public void ZombieAttackTheCops(GameObject cop, GameObject zombie) + public void RemoveFromList(GameObject zombie) { zombieList.Remove(zombie); Destroy(zombie); - CheckZombieCount(); - spawnPlayer.KillCop(cop); } - public void ZombieGotShoot(GameObject zombie) + public int ZombieNumber() { - zombieList.Remove(zombie); - Destroy(zombie); - CheckZombieCount(); + return zombieList.Count; } - private void CheckZombieCount() - { - if(zombieList.Count <= 0) - { - spawnPlayer.AllZomibesKilled(); - } - } + } + \ No newline at end of file From cd57150e690b278a837b608ae7b7a7357696e70b Mon Sep 17 00:00:00 2001 From: hab Date: Sat, 15 Apr 2023 09:24:02 +0200 Subject: [PATCH 4/4] Fixing (#1) fixing #1 --- Assets/Prefabs/Enemy Spawner.prefab | 77 +++++++++ Assets/Prefabs/Enemy Spawner.prefab.meta | 7 + Assets/Scenes/GameScene.unity | 204 ++++++++++++++--------- Assets/Scripts/Player/PlayerSpawning.cs | 8 +- 4 files changed, 220 insertions(+), 76 deletions(-) create mode 100644 Assets/Prefabs/Enemy Spawner.prefab create mode 100644 Assets/Prefabs/Enemy Spawner.prefab.meta diff --git a/Assets/Prefabs/Enemy Spawner.prefab b/Assets/Prefabs/Enemy Spawner.prefab new file mode 100644 index 0000000..7793b79 --- /dev/null +++ b/Assets/Prefabs/Enemy Spawner.prefab @@ -0,0 +1,77 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6246371829720322739 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6246371829720322748} + - component: {fileID: 6246371829720322749} + - component: {fileID: 6246371829720322750} + - component: {fileID: 6246371829720322751} + m_Layer: 0 + m_Name: Enemy Spawner + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6246371829720322748 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6246371829720322739} + m_LocalRotation: {x: -0, y: 1, z: -0, w: -0.00000016292068} + m_LocalPosition: {x: 0.24, y: 0, z: 39.440132} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6246371829720322749 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6246371829720322739} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c35afa73613ff3946be7fed53b4fa881, type: 3} + m_Name: + m_EditorClassIdentifier: + zombiePrefab: {fileID: 856601670117699726, guid: b14953694d54eea4eb66f453e525024c, type: 3} + zombieList: [] + enemysNumber: 5 + isZombieAttack: 0 +--- !u!65 &6246371829720322750 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6246371829720322739} + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 6.1, y: 0.5, z: 7.8093915} + m_Center: {x: 0, y: 0, z: 0.40469575} +--- !u!114 &6246371829720322751 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6246371829720322739} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e251059c5953f8249897732bc62da839, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Prefabs/Enemy Spawner.prefab.meta b/Assets/Prefabs/Enemy Spawner.prefab.meta new file mode 100644 index 0000000..7dfb38c --- /dev/null +++ b/Assets/Prefabs/Enemy Spawner.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f4da4732880517b4f8c1a91f4e46cc9b +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 283904c..02a785c 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -453,81 +453,11 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 ---- !u!1 &286861847 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 286861848} - - component: {fileID: 286861849} - - component: {fileID: 286861850} - - component: {fileID: 286861851} - m_Layer: 0 - m_Name: Enemy Spawner - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &286861848 +--- !u!4 &286861848 stripped Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 286861847} - m_LocalRotation: {x: -0, y: 1, z: -0, w: -0.00000016292068} - m_LocalPosition: {x: 0.24, y: 0, z: 39.440132} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 968253941} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &286861849 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 286861847} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c35afa73613ff3946be7fed53b4fa881, type: 3} - m_Name: - m_EditorClassIdentifier: - zombiePrefab: {fileID: 856601670117699726, guid: b14953694d54eea4eb66f453e525024c, type: 3} - zombieList: [] - enemysNumber: 5 - isZombieAttack: 0 ---- !u!65 &286861850 -BoxCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 286861847} - m_Material: {fileID: 0} - m_IsTrigger: 1 - m_Enabled: 1 - serializedVersion: 2 - m_Size: {x: 6.1, y: 0.5, z: 7.8093915} - m_Center: {x: 0, y: 0, z: 0.40469575} ---- !u!114 &286861851 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} + m_CorrespondingSourceObject: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + m_PrefabInstance: {fileID: 6246371829433612452} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 286861847} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: e251059c5953f8249897732bc62da839, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &335817951 GameObject: m_ObjectHideFlags: 0 @@ -555,7 +485,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 335817951} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: -1.2878588e-15, z: 58} + m_LocalPosition: {x: 0, y: -1.3100632e-15, z: 59} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -980,7 +910,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 611561436} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: -1.5099034e-15, z: 68} + m_LocalPosition: {x: 0, y: -1.5321078e-15, z: 69} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1782,9 +1712,76 @@ Transform: m_Children: - {fileID: 742329080} - {fileID: 286861848} + - {fileID: 1034361561} m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1034361560 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 968253941} + m_Modifications: + - target: {fileID: 6246371829720322739, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_Name + value: Enemy Spawner (1) + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalPosition.x + value: 0.2 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalPosition.z + value: 55.7 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalRotation.w + value: -0.00000016292068 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalRotation.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322749, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: enemysNumber + value: 8 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} +--- !u!4 &1034361561 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + m_PrefabInstance: {fileID: 1034361560} + m_PrefabAsset: {fileID: 0} --- !u!1 &1086009404 GameObject: m_ObjectHideFlags: 0 @@ -3077,6 +3074,63 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2142333987} m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1001 &6246371829433612452 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 968253941} + m_Modifications: + - target: {fileID: 6246371829720322739, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_Name + value: Enemy Spawner + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_RootOrder + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalPosition.x + value: 0.24 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalPosition.z + value: 39.440132 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalRotation.w + value: -0.00000016292068 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalRotation.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6246371829720322748, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: f4da4732880517b4f8c1a91f4e46cc9b, type: 3} --- !u!1001 &7322868460640539742 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Player/PlayerSpawning.cs b/Assets/Scripts/Player/PlayerSpawning.cs index c4fd9b5..d4e0541 100644 --- a/Assets/Scripts/Player/PlayerSpawning.cs +++ b/Assets/Scripts/Player/PlayerSpawning.cs @@ -6,10 +6,16 @@ public class PlayerSpawning : MonoBehaviour { [SerializeField] GameObject copPrefab; public List copList; + AudioController audioController; + + private void Start() + { + audioController = GameObject.Find("AudioSource").GetComponent(); + } public void Spawn(int gateValue, GateType gateType) { - //audioController.PlayGateSound(); + audioController.PlayGateSound(); if (gateType == GateType.ADDITION) { for (int i = 0; i < gateValue; i++)