diff options
Diffstat (limited to 'SurvivalTest/Assets/Scripts/Weapons/Weapon_Gun.cs')
-rw-r--r-- | SurvivalTest/Assets/Scripts/Weapons/Weapon_Gun.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/SurvivalTest/Assets/Scripts/Weapons/Weapon_Gun.cs b/SurvivalTest/Assets/Scripts/Weapons/Weapon_Gun.cs new file mode 100644 index 0000000..5517edd --- /dev/null +++ b/SurvivalTest/Assets/Scripts/Weapons/Weapon_Gun.cs @@ -0,0 +1,57 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 枪 +/// </summary> +public class Weapon_Gun : WeaponBase +{ + + public override string name => "枪"; + + public override string iconPath => "art/ui/weaponicon/gun"; + + public override AutoMode autoMode => AutoMode.Interval; + + public override float interval => 0.1f; + + private string prefabPath = "prefabs/bullet/bullet"; + + private int index = 0; + + TestPeaceMakerBullet CreateBullet(CrewScript crew, Vector2 dir, float speed, float lifeTime) + { + TestPeaceMakerBullet bullet = UnityEngine.Object.Instantiate<TestPeaceMakerBullet>(ResourceManager.Instance.Load< TestPeaceMakerBullet>(prefabPath)); + + bullet.transform.position = crew.arrow.position + new Vector3(crew.aimDirection.x, crew.aimDirection.y, 0) * -0.3f; + + bullet.Set(dir, speed, lifeTime); + bullet.gameObject.SetActive(true); + + return bullet; + } + + public override void OnTrigger(GameObject owner) + { + CrewScript crew = owner.GetComponent<CrewScript>(); + + index++; + index = index % 3; + + if(index == 0) + { + CreateBullet(crew, TestMathHelper.Rotate(crew.aimDirection, -10 * Mathf.Deg2Rad), 12f, 2f); + } + else if(index == 1) + { + CreateBullet(crew, crew.aimDirection, 12f, 2f); + } + else if(index == 2) + { + CreateBullet(crew, TestMathHelper.Rotate(crew.aimDirection, 10 * Mathf.Deg2Rad), 12f, 2f); + } + + } + +}
\ No newline at end of file |