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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
public float distance = 10.0f;
//private CharacterController cc;
float velocityY = 0.0f;
const float gravity = 9.8f;
public HookBehaviour hook;
private Rigidbody rb;
private DistanceJoint3D joint;
private bool isWired;
#if UNITY_EDITOR
private void OnDrawGizmos()
{
Gizmos.DrawLine(transform.position, (transform.position - Camera.main.transform.position) * 10);
}
#endif
private void Start()
{
//cc = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
joint = GetComponent<DistanceJoint3D>();
rb = GetComponent<Rigidbody>();
}
private void Update()
{
float vertical = Input.GetAxis("Vertical");
float horizontal = Input.GetAxis("Horizontal");
if (Input.GetMouseButtonDown(1))
{
if (!hook.gameObject.activeSelf)
{
FireHook();
}
else
ReturnHook();
}
if (!isWired)
{
/*
if (Input.GetButtonDown("Jump") && cc.isGrounded)
velocityY = 5.0f;
if (!cc.isGrounded)
velocityY -= gravity * Time.deltaTime;
cc.Move(horizontal * transform.right + vertical * transform.forward + new Vector3(0, velocityY, 0) * Time.deltaTime);
*/
}
else
{
}
}
private void LateUpdate()
{
}
private void FireHook()
{
joint.enabled = false;
hook.gameObject.SetActive(true);
hook.transform.position = transform.position;
hook.EnableHook((transform.position - Camera.main.transform.position).normalized * 200);
}
private void ReturnHook()
{
joint.enabled = false;
hook.DisableHook();
isWired = false;
rb.useGravity = true;
//cc.enabled = true;
}
public void ActiveWire()
{
joint.enabled = true;
joint.distance = Vector3.Distance(transform.position, hook.transform.position);
isWired = true;
rb.useGravity = false;
//cc.enabled = false;
}
}