summaryrefslogtreecommitdiff
path: root/GameCode/BulletPoint.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/BulletPoint.cs
+ init
Diffstat (limited to 'GameCode/BulletPoint.cs')
-rw-r--r--GameCode/BulletPoint.cs56
1 files changed, 56 insertions, 0 deletions
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>();
+ Gun obj = gun;
+ obj.ShootPojectileAction = (Action<GameObject>)Delegate.Combine(obj.ShootPojectileAction, new Action<GameObject>(Fire));
+ }
+
+ private void Attack()
+ {
+ gun.Attack(1f, forceAttack: true);
+ }
+
+ private void Fire(GameObject projectile)
+ {
+ move = projectile.GetComponent<MoveTransform>();
+ }
+
+ 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();
+ }
+ }
+ }
+}