blob: 1f1839f95e63f8c56c9288a114823b3efcc44f4f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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);
}
}
}
|