From d69adc7009c7953749b59ace2518c0a7c99faa47 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 24 Apr 2022 19:10:43 +0800 Subject: + light saber --- .../Scripts/Equips/LightSaber/Equip_LightSaber.cs | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 SurvivalTest/Assets/Scripts/Equips/LightSaber/Equip_LightSaber.cs (limited to 'SurvivalTest/Assets/Scripts/Equips/LightSaber/Equip_LightSaber.cs') diff --git a/SurvivalTest/Assets/Scripts/Equips/LightSaber/Equip_LightSaber.cs b/SurvivalTest/Assets/Scripts/Equips/LightSaber/Equip_LightSaber.cs new file mode 100644 index 0000000..9066884 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Equips/LightSaber/Equip_LightSaber.cs @@ -0,0 +1,63 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Equip_LightSaber : EquipBase +{ + public override string name => "¹â½£"; + + public override string iconPath => "art/ui/equipicon/light_saber"; + + public override AutoMode autoMode => AutoMode.Condition; + + private string lightSaberPrefabPath = "prefabs/weapon/light_saber"; + + private bool isWielding = false; + + private LightSaber m_LightSaber; + + private TopDownTransform m_TopDownTransform; + + private float m_Dist = 0.2f; + + public override void OnInitialize(GameObject owner) + { + m_LightSaber = UnityEngine.Object.Instantiate(ResourceManager.Instance.Load(lightSaberPrefabPath)); + m_TopDownTransform = m_LightSaber.gameObject.GetComponent(); + SetLightSaberPositionAndRotation(owner.GetComponent()); + m_LightSaber.gameObject.SetActive(false); + } + + public override bool CheckCondition(GameObject owner) + { + return true; + } + + public override void OnTrigger(GameObject owner) + { + if (isWielding) + return; + isWielding = true; + + m_LightSaber.gameObject.SetActive(true); + } + + public override void OnStop(GameObject owner) + { + isWielding = false; + m_LightSaber.gameObject.SetActive(false); + } + + public override void Update(GameObject owner) + { + CrewScript crew = owner.GetComponent(); + SetLightSaberPositionAndRotation(crew); + } + + void SetLightSaberPositionAndRotation(CrewScript crew) + { + m_LightSaber.transform.position = crew.arrow.position + new Vector3(crew.aimDirection.x, crew.aimDirection.y, 0) * m_Dist; + m_LightSaber.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(crew.aimDirection.y, crew.aimDirection.x) * Mathf.Rad2Deg); + } + +} \ No newline at end of file -- cgit v1.1-26-g67d0