From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/BulletPoint.cs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 GameCode/BulletPoint.cs (limited to 'GameCode/BulletPoint.cs') diff --git a/GameCode/BulletPoint.cs b/GameCode/BulletPoint.cs new file mode 100644 index 0000000..d7a9157 --- /dev/null +++ b/GameCode/BulletPoint.cs @@ -0,0 +1,56 @@ +using System; +using UnityEngine; + +public class BulletPoint : MonoBehaviour +{ + public LayerMask mask; + + private Gun gun; + + private MoveTransform move; + + private ProjectileHit hit; + + private float counter = 5f; + + private void Start() + { + gun = GetComponent(); + Gun obj = gun; + obj.ShootPojectileAction = (Action)Delegate.Combine(obj.ShootPojectileAction, new Action(Fire)); + } + + private void Attack() + { + gun.Attack(1f, forceAttack: true); + } + + private void Fire(GameObject projectile) + { + move = projectile.GetComponent(); + } + + private void Update() + { + if ((bool)move) + { + counter = 0f; + Vector3 vector = base.transform.position - base.transform.root.position; + RaycastHit2D raycastHit2D = Physics2D.Raycast(base.transform.root.position, vector, vector.magnitude, mask, -10000f); + Vector3 vector2 = base.transform.position; + if (raycastHit2D.transform != null) + { + vector2 = raycastHit2D.point - (Vector2)vector.normalized * 0.1f; + } + move.velocity = Vector2.Lerp(move.velocity, (vector2 - move.transform.position) * 50f, TimeHandler.deltaTime * 50f); + } + else + { + counter += TimeHandler.deltaTime; + if (counter > 2f) + { + Attack(); + } + } + } +} -- cgit v1.1-26-g67d0