summaryrefslogtreecommitdiff
path: root/GameCode/Holding.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/Holding.cs
+ init
Diffstat (limited to 'GameCode/Holding.cs')
-rw-r--r--GameCode/Holding.cs75
1 files changed, 75 insertions, 0 deletions
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<Player>();
+ holdable.GetComponent<Holdable>().holder = player.data;
+ handPos = GetComponentInChildren<HandPos>().transform;
+ rig = GetComponent<PlayerVelocity>();
+ input = GetComponent<GeneralInput>();
+ data = GetComponent<CharacterData>();
+ if ((bool)holdable)
+ {
+ gun = holdable.GetComponent<Gun>();
+ GetComponentInChildren<WeaponHandler>().gun = holdable.GetComponent<Gun>();
+ }
+ }
+
+ 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);
+ }
+ }
+}