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/TracerRound.cs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 GameCode/TracerRound.cs (limited to 'GameCode/TracerRound.cs') diff --git a/GameCode/TracerRound.cs b/GameCode/TracerRound.cs new file mode 100644 index 0000000..201a5f7 --- /dev/null +++ b/GameCode/TracerRound.cs @@ -0,0 +1,48 @@ +using UnityEngine; + +public class TracerRound : MonoBehaviour +{ + public GameObject bullet; + + public GameObject bulletSpawnPos; + + private TracerTarget target; + + private MoveTransform move; + + private bool done; + + private void Start() + { + move = GetComponent(); + bullet = Object.Instantiate(bullet, bulletSpawnPos.transform.position, bulletSpawnPos.transform.rotation); + bullet.GetComponent().damage *= base.transform.localScale.x; + GetComponentInParent().CopySpawnedAttackTo(bullet); + target = bullet.GetComponent(); + GetComponentInParent().AddHitActionWithData(Hit); + bullet.GetComponentInParent().AddHitActionWithData(Hit); + } + + public void Hit(HitInfo hit) + { + if ((bool)hit.transform.root.GetComponent()) + { + base.transform.SetParent(null); + base.gameObject.AddComponent().seconds = 10f; + base.gameObject.AddComponent().target = hit.transform; + } + } + + private void Update() + { + if (target != null) + { + target.SetPos(base.transform.position, Vector3.Cross(Vector3.forward, base.transform.forward), move); + } + if (bullet == null && !done) + { + done = true; + GetComponentInChildren().Stop(); + } + } +} -- cgit v1.1-26-g67d0