diff --git a/Assets/Scenes/Level_01.unity b/Assets/Scenes/Level_01.unity index ffaae3f427e991c45ea621f3d331bc4d0633a5c6..02b8d498bb94ee0f2c378b22cf0441a03c318ba8 100644 --- a/Assets/Scenes/Level_01.unity +++ b/Assets/Scenes/Level_01.unity @@ -203,6 +203,138 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9637472} m_CullTransparentMesh: 1 +--- !u!1 &33945473 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: c9a73f42c15ac4f48a92c5f435471f7f, type: 3} + m_PrefabInstance: {fileID: 216831668} + m_PrefabAsset: {fileID: 0} +--- !u!64 &33945475 +MeshCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 33945473} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 4 + m_Convex: 1 + m_CookingOptions: 30 + m_Mesh: {fileID: 0} +--- !u!114 &33945476 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 33945473} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cf07be16e2437734f8bb656151099f16, type: 3} + m_Name: + m_EditorClassIdentifier: + player: {fileID: 624092162} + swordCollider: {fileID: 33945475} + damagePerShot: 300 + spinSpeed: 500 + spinDuration: 0.5 +--- !u!82 &33945477 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 33945473} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 8300000, guid: 352735f28fe99b643a447f955cee8df3, type: 3} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + 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 &43179831 GameObject: m_ObjectHideFlags: 0 @@ -478,147 +610,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 50798759} m_CullTransparentMesh: 1 ---- !u!1 &65180353 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 65180354} - - component: {fileID: 65180359} - - component: {fileID: 65180360} - m_Layer: 0 - m_Name: SwordEnd - m_TagString: PlayerWeapon - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 0 ---- !u!4 &65180354 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 65180353} - m_LocalRotation: {x: 0.000680983, y: -0, z: -0, w: 0.99999976} - m_LocalPosition: {x: 0.165, y: 0.296, z: 0.752} - m_LocalScale: {x: 1.0000001, y: 1.0000001, z: 0.99999994} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 624092168} - m_RootOrder: 6 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!82 &65180359 -AudioSource: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 65180353} - m_Enabled: 1 - serializedVersion: 4 - OutputAudioMixerGroup: {fileID: 24300002, guid: 5b84db49d40ea449aa4f3e3bd229ab5b, type: 2} - m_audioClip: {fileID: 8300000, guid: 352735f28fe99b643a447f955cee8df3, type: 3} - m_PlayOnAwake: 0 - m_Volume: 1 - m_Pitch: 1 - Loop: 0 - 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!114 &65180360 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 65180353} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: cf07be16e2437734f8bb656151099f16, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!224 &74239851 stripped RectTransform: m_CorrespondingSourceObject: {fileID: 22475538, guid: 751f7137cfffd4a16b1a4c191e687d64, type: 3} @@ -2704,21 +2695,6 @@ Transform: m_Father: {fileID: 1621540566} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &450320207 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 450320205} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 27c63be2a8918c741863160b9d9da122, type: 3} - m_Name: - m_EditorClassIdentifier: - damagePerShot: 10 - timeBetweenBullets: 1 - range: 20 --- !u!199 &450320208 ParticleSystemRenderer: serializedVersion: 6 @@ -2835,6 +2811,14 @@ LineRenderer: m_Positions: - {x: 0, y: 0, z: 0} - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 0} m_Parameters: serializedVersion: 3 widthMultiplier: 1 @@ -7840,9 +7824,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cc6a0829d09b1c0408328c4fdef54b0c, type: 3} m_Name: m_EditorClassIdentifier: - damagePerShot: 10 - timeBetweenBullets: 10.5 - range: 0.2 + damagePerShot: 30 + timeBetweenBullets: 1 + range: 10 --- !u!1 &453799214 GameObject: m_ObjectHideFlags: 0 @@ -8951,6 +8935,24 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8ea934e3b4cb2924ab76d641d63f0576, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &624092178 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 624092162} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1a569a18903c53b4dbe48b47e7e9a3c2, type: 3} + m_Name: + m_EditorClassIdentifier: + weaponIdx: 0 + Rifle: {fileID: 1828627133} + RifleEnd: {fileID: 1003343662} + Shotgun: {fileID: 2003766919} + Bow: {fileID: 1391600422} + Sword: {fileID: 33945473} --- !u!114 &624169576 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 6488902045712596028, guid: c133a0e3fc4f48c43a4306ef7a127b9a, type: 3} @@ -19228,6 +19230,11 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1825124403} m_CullTransparentMesh: 1 +--- !u!1 &1828627133 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 100002, guid: f1d84cc28597f5641a3d9cbc4df7e306, type: 3} + m_PrefabInstance: {fileID: 1003343661} + m_PrefabAsset: {fileID: 0} --- !u!1 &1841146650 GameObject: m_ObjectHideFlags: 0 @@ -19908,6 +19915,11 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1987641286} m_CullTransparentMesh: 0 +--- !u!1 &2003766919 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: abd916789bc97d749bbd99ecea64cc61, type: 3} + m_PrefabInstance: {fileID: 1389017764} + m_PrefabAsset: {fileID: 0} --- !u!1 &2020771695 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Managers/EnemyManager.cs b/Assets/Scripts/Managers/EnemyManager.cs index e854f531ade7c3c76631f4ff5974faf19c78ddc3..e6d3ffbf337bb764625696b9d50e844f7b4e9e01 100644 --- a/Assets/Scripts/Managers/EnemyManager.cs +++ b/Assets/Scripts/Managers/EnemyManager.cs @@ -41,7 +41,8 @@ public class EnemyManager : MonoBehaviour public void setQuestNum(int questNum) { this.questNum = questNum; - if (questNum == 4) { + if (questNum == 4) + { Factory.FactoryMethod(3, spawnPoints[3].transform); } } diff --git a/Assets/Scripts/Player/Rifle.cs b/Assets/Scripts/Player/Rifle.cs index 4c15fe74f4bb9f70520cfb8e35f1ed3de19165da..2816829a1ae67bcf022d096452ece982653f32cc 100644 --- a/Assets/Scripts/Player/Rifle.cs +++ b/Assets/Scripts/Player/Rifle.cs @@ -1,4 +1,4 @@ -using UnityEngine; + using UnityEngine; public class Rifle : MonoBehaviour { diff --git a/Assets/Scripts/Player/Shotgun.cs b/Assets/Scripts/Player/Shotgun.cs index db3aec026b7b833c8a33a033ffaf8176ad9a4687..fd9a6aa2f8cb15c43105d78cef54cff5d8ca7be4 100644 --- a/Assets/Scripts/Player/Shotgun.cs +++ b/Assets/Scripts/Player/Shotgun.cs @@ -4,12 +4,12 @@ using UnityEngine; public class Shotgun : MonoBehaviour { - public int damagePerShot = 10; + public int damagePerShot = 30; public float timeBetweenBullets = 1f; public float range = 0.2f; float timer; - Ray shootRay = new Ray(); + //Ray shootRay = new Ray(); RaycastHit shootHit; int shootableMask; ParticleSystem gunParticles; @@ -58,66 +58,55 @@ public class Shotgun : MonoBehaviour gunLight.enabled = false; } + public void EnableEffects() + { + //enable line renderer + gunLine.enabled = true; + + //enable light + gunLight.enabled = true; + } public void Shoot() { timer = 0f; - //Play audio gunAudio.Play(); - //enable Light gunLight.enabled = true; - //Play gun particle gunParticles.Stop(); gunParticles.Play(); - //enable Line renderer dan set first position gunLine.enabled = true; - gunLine.positionCount = 5; - gunLine.SetPosition(0, transform.position); - //Set posisi ray shoot dan direction - shootRay.origin = transform.position; - shootRay.direction = transform.forward; + gunLine.SetPosition(0, transform.position); + gunLine.SetPosition(2, transform.position); + gunLine.SetPosition(4, transform.position); + gunLine.SetPosition(6, transform.position); + gunLine.SetPosition(8, transform.position); - //Lakukan raycast jika mendeteksi id nemy hit apapun for (int idx = 0; idx < 5; idx++) { Vector3 direction = transform.forward; - //Add random spread to the bullet's trajectory - Vector3 spread = Vector3.zero; - spread+= transform.right * Random.Range(-1f, 1f); - spread+= transform.up * Random.Range(-1f, 1f); - - // Set direction - direction += spread.normalized * Random.Range(0f, 0.2f); + direction.x += idx * 0.1f; - //Create a new shoot ray with the randomized direction - Ray shootRayMultiple = new Ray(shootRay.origin, direction); + Ray shootRayMultiple = new Ray(transform.position, direction); - //Lakukan raycast jika mendeteksi id nemy hit apapun if (Physics.Raycast(shootRayMultiple, out shootHit, range, shootableMask)) { - //Lakukan raycast hit hace component Enemyhealth EnemyHealth enemyHealth = shootHit.collider.GetComponent<EnemyHealth>(); if (enemyHealth != null) { - //Lakukan Take Damage enemyHealth.TakeDamage(damagePerShot, shootHit.point); } - - //Set line end position ke hit position - gunLine.SetPosition(idx, shootHit.point); - Debug.DrawLine(transform.position, shootHit.point, Color.green, 1f); + Debug.Log(shootHit.point); + gunLine.SetPosition(idx*2+1, shootHit.point); } - //set line end position ke range freom barrel else { - gunLine.SetPosition(idx, shootRayMultiple.origin + shootRayMultiple.direction * range); - Debug.DrawLine(transform.position, transform.position + direction * range, Color.red, 1f); + gunLine.SetPosition(idx * 2 + 1, shootRayMultiple.origin + shootRayMultiple.direction * range); } } } diff --git a/Assets/Scripts/Player/Sword.cs b/Assets/Scripts/Player/Sword.cs index 1b619a77a3c1d8e81585da1fb3a5e8f416fbcf1b..b86da41d79a9621f699b1643f765c22ae494a4d3 100644 --- a/Assets/Scripts/Player/Sword.cs +++ b/Assets/Scripts/Player/Sword.cs @@ -4,73 +4,69 @@ using UnityEngine; public class Sword : MonoBehaviour { - // public GameObject sword; - // public int damagePerShot = 20; - // public float spinSpeed = 100f; - // public float spinDuration = 0.5f; + public GameObject player; + public MeshCollider swordCollider; + public int damagePerShot = 20; + public float spinSpeed = 500f; + public float spinDuration = 0.5f; - // private bool isSpinning = false; - // private float timer = 0f; - // private float cooldown = 0f; - // private Transform playerTransform; + private bool isSpinning = false; + private float timer = 0f; + private float cooldown = 0f; + private Transform playerTransform; - // private int shootableMask; - // private AudioSource swordAudio; + private AudioSource audioSource; - // // Start is called before the first frame update - // void Start() - // { - // playerTransform = transform.Find("Player"); - // } + private void Start() + { + playerTransform = player.transform; + audioSource = GetComponent<AudioSource>(); + } - // void Awake() { - // shootableMask = LayerMask.GetMask("Shootable"); - // swordAudio = GetComponent<AudioSource>(); - // } + void Update() { + swordCollider.enabled = true; + if (Input.GetButtonDown("Fire1") && !isSpinning && Time.timeScale != 0) + { + isSpinning = true; + timer = 0f; + cooldown = 0f; + } - // // Update is called once per frame - // void Update() - // { - // timer += Time.deltaTime; + if (isSpinning) + { + audioSource.loop = true; + audioSource.Play(); + timer += Time.deltaTime; + cooldown += Time.deltaTime; + if (timer < spinDuration) + { + playerTransform.Rotate(Vector3.up * spinSpeed * Time.deltaTime); + } + else + { + isSpinning = false; + } + } + else + { + audioSource.loop = false; + if (cooldown < spinDuration) + { + swordCollider.enabled = true; + } + } + } - // if (Input.GetButton("Fire1") && cooldown <= 0 && Time.timeScale != 0) - // { - // isSpinning = true; - // timer = spinDuration; - // cooldown = spinDuration; - // } + void OnTriggerEnter(Collider collision) + { + if (collision.gameObject.tag == "Player") { + return; + } - // if (isSpinning) - // { - // swordAudio.Play(); - // playerTransform.Rotate(Vector3.up * spinSpeed * Time.deltaTime); - // timer -= Time.deltaTime; - - // if (timer <= 0f) - // { - // isSpinning = false; - // playerTransform.rotation = Quaternion.identity; - // } - // } - - // if (cooldown > 0) - // { - // cooldown -= Time.deltaTime; - // } - // } - - // void OnTriggerEnter(Collider other) - // { - // if (isSpinning) - // { - // if (other.gameObject.tag == "Enemy") - // { - // EnemyHealth enemyHealth = other.gameObject.GetComponent<EnemyHealth>(); - // if (enemyHealth != null) - // { - // enemyHealth.TakeDamage(damagePerShot); - // } - // } - // } - // } + if (collision.gameObject.tag == "Enemy") + { + Debug.Log("Enemy hit"); + collision.gameObject.GetComponent<EnemyHealth>().TakeDamage(damagePerShot); + } + } } diff --git a/Assets/Scripts/Quest/QuestManager.cs b/Assets/Scripts/Quest/QuestManager.cs index 07b63e605278efd8b975f739962eda7ae3eb32c4..df00913e1aa7f51a4454c2061927fa2d0bf82d04 100644 --- a/Assets/Scripts/Quest/QuestManager.cs +++ b/Assets/Scripts/Quest/QuestManager.cs @@ -98,14 +98,9 @@ public class QuestManager : MonoBehaviour } else if (!hasAppendScoreboard) { // End game // Add to scoreboard - if (nh.getPlayerName() != "") { - Debug.Log("Add to scoreboard"); - Time.timeScale = 1f; - - hasAppendScoreboard = true; - t = TimeSpan.FromSeconds(time); - sm.AddScore(new Score(nh.getPlayerName(), t.ToString("hh':'mm':'ss"))); - } + hasAppendScoreboard = true; + t = TimeSpan.FromSeconds(time); + sm.AddScore(new Score("", t.ToString("hh':'mm':'ss"))); } if (questItems[activeQuestIdx].isFinished() && activeQuestIdx < questItems.Count - 1) @@ -159,10 +154,10 @@ public class QuestManager : MonoBehaviour else if (!isQuestFinish) { isQuestFinish = true; - Time.timeScale = 0f; - + enemyManager.killAllEnemies(); StartCoroutine(LoadVictoryScene()); + } } diff --git a/Assets/Scripts/Save/SaveHandler.cs b/Assets/Scripts/Save/SaveHandler.cs index 72d7d8401920e783eab96e87defc6a4f29247995..5dfa76aeaf8d18d52e1b6230b17b6fad06bb9262 100644 --- a/Assets/Scripts/Save/SaveHandler.cs +++ b/Assets/Scripts/Save/SaveHandler.cs @@ -73,7 +73,7 @@ public class SaveHandler : MonoBehaviour GameObject player = GameObject.FindGameObjectWithTag("Player"); QuestManager questManager = GetComponent<QuestManager>(); SaveData data = (SaveData)SaveManager.Load(fileName); - data.playerPosition.y = 2; + data.playerPosition.y = 0.00001f; Debug.Log(data.playerPosition); player.transform.position = data.playerPosition; player.transform.rotation = data.playerRotation; diff --git a/Assets/WeaponHandling.cs b/Assets/WeaponHandling.cs new file mode 100644 index 0000000000000000000000000000000000000000..d4e073be476a79ec6197f60ab387774c2580aabe --- /dev/null +++ b/Assets/WeaponHandling.cs @@ -0,0 +1,278 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class WeaponHandling : MonoBehaviour +{ + public int weaponIdx = 0; // 0= rifle, 1= shotgun, 2= sword, 3= bow + public GameObject Rifle; + public GameObject RifleEnd; + public GameObject Shotgun; + public GameObject Bow; + public GameObject Sword; + private PlayerMovement Player; + // Start is called before the first frame update + void Start() + { + Player = GetComponent<PlayerMovement>(); + } + // Update is called once per frame + void Update() + { + if (Input.GetKeyDown("1")) + { + weaponIdx = 0; + Rifle.SetActive(true); + RifleEnd.SetActive(true); + Shotgun.SetActive(false); + Bow.SetActive(false); + Sword.SetActive(false); + return; + } + if (Input.GetKeyDown("2") && Player.shotgun == 1) + { + weaponIdx = 1; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(true); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + if (Input.GetKeyDown("3") && Player.sword == 1) + { + weaponIdx = 2; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Bow.SetActive(false); + Sword.SetActive(true); + return; + } + if (Input.GetKeyDown("4") && Player.bow == 1) + { + weaponIdx = 3; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Bow.SetActive(true); + Sword.SetActive(false); + return; + } + // scroll change weapon + if (weaponIdx==0 && Input.GetAxis("Mouse ScrollWheel") < 0f) // downward + { + if (Player.shotgun == 1) + { + weaponIdx = 1; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(true); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + else if (Player.sword == 1) + { + weaponIdx = 2; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Sword.SetActive(true); + Bow.SetActive(false); + return; + } + else if (Player.bow == 1) + { + Debug.Log("Lol"); + weaponIdx = 3; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(true); + return; + } + else { + weaponIdx = 0; + return; + } + } + //upward + if (weaponIdx == 0 && Input.GetAxis("Mouse ScrollWheel") > 0f) + { + if (Player.bow == 1) + { + weaponIdx = 3; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(true); + return; + } + else if (Player.sword == 1) + { + weaponIdx = 2; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Sword.SetActive(true); + Bow.SetActive(false); + return; + } + else if (Player.shotgun == 1) + { + weaponIdx = 1; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(true); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + else + { + weaponIdx = 0; + return; + } + } + // downward shotgun + if (weaponIdx == 1 && Input.GetAxis("Mouse ScrollWheel") < 0f) + { + if (Player.sword == 1) + { + weaponIdx = 2; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Sword.SetActive(true); + Bow.SetActive(false); + return; + } + else if (Player.bow == 1) + { + weaponIdx = 3; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(true); + return; + } + else + { + Debug.Log("Lol"); + weaponIdx = 0; + Rifle.SetActive(true); + RifleEnd.SetActive(true); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + } + // upward shotgun + if (weaponIdx == 1 && Input.GetAxis("Mouse ScrollWheel") > 0f) + { + weaponIdx = 0; + Rifle.SetActive(true); + RifleEnd.SetActive(true); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + // downward sword + if (weaponIdx == 2 && Input.GetAxis("Mouse ScrollWheel") < 0f) + { + if (Player.bow == 1) + { + weaponIdx = 3; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(true); + return; + } + else + { + weaponIdx = 0; + Rifle.SetActive(true); + RifleEnd.SetActive(true); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + } + // upward sword + if (weaponIdx == 2 && Input.GetAxis("Mouse ScrollWheel") > 0f) + { + if (Player.shotgun == 1) + { + weaponIdx = 1; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(true); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + else + { + weaponIdx = 0; + Rifle.SetActive(true); + RifleEnd.SetActive(true); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + } + // downward bow + if (weaponIdx == 3 && Input.GetAxis("Mouse ScrollWheel") < 0f) + { + weaponIdx = 0; + Rifle.SetActive(true); + RifleEnd.SetActive(true); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + // upward bow + if (weaponIdx == 3 && Input.GetAxis("Mouse ScrollWheel") > 0f) + { + if (Player.sword == 1) + { + weaponIdx = 2; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(false); + Sword.SetActive(true); + Bow.SetActive(false); + return; + } + else if (Player.shotgun == 1) { + weaponIdx = 1; + Rifle.SetActive(false); + RifleEnd.SetActive(false); + Shotgun.SetActive(true); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + else { + weaponIdx = 0; + Rifle.SetActive(true); + RifleEnd.SetActive(true); + Shotgun.SetActive(false); + Sword.SetActive(false); + Bow.SetActive(false); + return; + } + } + } +} diff --git a/Assets/WeaponHandling.cs.meta b/Assets/WeaponHandling.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..c7f3a86691f77d7e84c852b6ef39a3adcd1ed3cf --- /dev/null +++ b/Assets/WeaponHandling.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1a569a18903c53b4dbe48b47e7e9a3c2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: