diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/TracerRound.cs |
+ init
Diffstat (limited to 'GameCode/TracerRound.cs')
-rw-r--r-- | GameCode/TracerRound.cs | 48 |
1 files changed, 48 insertions, 0 deletions
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<MoveTransform>(); + bullet = Object.Instantiate(bullet, bulletSpawnPos.transform.position, bulletSpawnPos.transform.rotation); + bullet.GetComponent<ProjectileHit>().damage *= base.transform.localScale.x; + GetComponentInParent<SpawnedAttack>().CopySpawnedAttackTo(bullet); + target = bullet.GetComponent<TracerTarget>(); + GetComponentInParent<ProjectileHit>().AddHitActionWithData(Hit); + bullet.GetComponentInParent<ProjectileHit>().AddHitActionWithData(Hit); + } + + public void Hit(HitInfo hit) + { + if ((bool)hit.transform.root.GetComponent<Player>()) + { + base.transform.SetParent(null); + base.gameObject.AddComponent<RemoveAfterSeconds>().seconds = 10f; + base.gameObject.AddComponent<FollowTransform>().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<ParticleSystem>().Stop(); + } + } +} |