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/Thruster.cs |
+ init
Diffstat (limited to 'GameCode/Thruster.cs')
-rw-r--r-- | GameCode/Thruster.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/GameCode/Thruster.cs b/GameCode/Thruster.cs new file mode 100644 index 0000000..0c595d1 --- /dev/null +++ b/GameCode/Thruster.cs @@ -0,0 +1,84 @@ +using UnityEngine; + +public class Thruster : MonoBehaviour +{ + public float force; + + public float drag; + + public float pow = 1f; + + public float physicsObjectM = 1f; + + private FollowLocalPos follow; + + private Rigidbody2D rig; + + private Vector2 startForward; + + private NetworkPhysicsObject pushed; + + private Player player; + + private bool checkedForPlayer; + + private void Start() + { + force *= Mathf.Pow(base.transform.localScale.x, pow); + drag *= Mathf.Pow(base.transform.localScale.x, pow); + follow = GetComponent<FollowLocalPos>(); + if ((bool)follow.target) + { + pushed = follow.target.gameObject.GetComponent<NetworkPhysicsObject>(); + } + float num = 1f; + if (!follow.targetPlayer) + { + num = 0.2f; + } + else if ((bool)pushed) + { + num = 0.5f; + } + ParticleSystem.MainModule main = GetComponentInChildren<ParticleSystem>().main; + main.duration *= num; + GetComponent<DelayEvent>().time *= num; + GetComponent<RemoveAfterSeconds>().seconds *= num; + startForward = base.transform.forward; + } + + private void FixedUpdate() + { + if (!follow) + { + return; + } + if ((bool)follow.target) + { + if ((bool)player) + { + if ((bool)player) + { + player.data.healthHandler.TakeForce(startForward * force, ForceMode2D.Force); + } + else + { + rig.AddForce(startForward * force, ForceMode2D.Force); + } + } + else if (!checkedForPlayer) + { + player = follow.target.transform.root.GetComponent<Player>(); + checkedForPlayer = true; + if (!player && !pushed) + { + base.enabled = false; + } + } + } + if ((bool)pushed && pushed.photonView.IsMine) + { + pushed.RPCA_SendForce(base.transform.forward * force * physicsObjectM, pushed.transform.InverseTransformPoint(base.transform.position)); + } + } +} |