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/Holding.cs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 GameCode/Holding.cs (limited to 'GameCode/Holding.cs') diff --git a/GameCode/Holding.cs b/GameCode/Holding.cs new file mode 100644 index 0000000..1f1839f --- /dev/null +++ b/GameCode/Holding.cs @@ -0,0 +1,75 @@ +using UnityEngine; + +public class Holding : MonoBehaviour +{ + public float force; + + public float drag; + + public Holdable holdable; + + private Transform handPos; + + private PlayerVelocity rig; + + private GeneralInput input; + + private CharacterData data; + + private Player player; + + private Gun gun; + + private bool hasSpawnedGun; + + public void Awake() + { + if (hasSpawnedGun) + { + Object.Destroy(holdable.gameObject); + } + hasSpawnedGun = true; + holdable = Object.Instantiate(holdable, base.transform.position, Quaternion.identity); + player = GetComponent(); + holdable.GetComponent().holder = player.data; + handPos = GetComponentInChildren().transform; + rig = GetComponent(); + input = GetComponent(); + data = GetComponent(); + if ((bool)holdable) + { + gun = holdable.GetComponent(); + GetComponentInChildren().gun = holdable.GetComponent(); + } + } + + private void Start() + { + if ((bool)holdable) + { + holdable.SetTeamColors(PlayerSkinBank.GetPlayerSkinColors(player.playerID), player); + } + } + + private void FixedUpdate() + { + if ((bool)holdable && (bool)holdable.rig) + { + holdable.rig.AddForce((handPos.transform.position + (Vector3)rig.velocity * 0.04f - holdable.transform.position) * force * holdable.rig.mass, ForceMode2D.Force); + holdable.rig.AddForce(holdable.rig.velocity * (0f - drag) * holdable.rig.mass, ForceMode2D.Force); + holdable.rig.transform.rotation = Quaternion.LookRotation(Vector3.forward, handPos.transform.forward); + } + } + + private void Update() + { + } + + private void OnDestroy() + { + if ((bool)holdable) + { + Object.Destroy(holdable.gameObject); + } + } +} -- cgit v1.1-26-g67d0