diff options
Diffstat (limited to 'SurvivalTest/Assets/Scripts/Weapons/LightSaber/Weapon_LightSaber.cs')
-rw-r--r-- | SurvivalTest/Assets/Scripts/Weapons/LightSaber/Weapon_LightSaber.cs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/SurvivalTest/Assets/Scripts/Weapons/LightSaber/Weapon_LightSaber.cs b/SurvivalTest/Assets/Scripts/Weapons/LightSaber/Weapon_LightSaber.cs new file mode 100644 index 0000000..ad942f3 --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Weapons/LightSaber/Weapon_LightSaber.cs @@ -0,0 +1,63 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Weapon_LightSaber : WeaponBase +{ + public override string name => "¹â½£"; + + public override string iconPath => "art/ui/weaponicon/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<LightSaber>(ResourceManager.Instance.Load<LightSaber>(lightSaberPrefabPath)); + m_TopDownTransform = m_LightSaber.gameObject.GetComponent<TopDownTransform>(); + SetLightSaberPositionAndRotation(owner.GetComponent<CrewScript>()); + 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<CrewScript>(); + 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 |