-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHoldable.cs
More file actions
130 lines (105 loc) · 3.31 KB
/
Copy pathHoldable.cs
File metadata and controls
130 lines (105 loc) · 3.31 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Holdable : MonoBehaviour
{
public bool Holded;
public Transform plyr;
public Vector3 offset;
public Animator animator;
public Rigidbody2D rb;
public float speed;
public Camera cam;
Vector2 movement;
Vector2 mousepos;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
mousepos = cam.ScreenToWorldPoint(Input.mousePosition);
Vector2 lookDir = mousepos - rb.position;
float x = Mathf.Abs(lookDir.x);
float y = Mathf.Abs(lookDir.y);
if (Input.GetButtonDown("Fire1") && Holded == true)
{
FindObjectOfType<PlayerMoves>().Holdrot();
Debug.Log("pressed");
}
if (Input.GetButtonUp("Fire1") && Holded == true)
{
speed = (x + y) *1.5f;
Holded = false;
gameObject.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
rb.velocity = transform.right * speed;
FindObjectOfType<PlayerMoves>().Holdrotd();
FindObjectOfType<PlayerMoves>().cantholdreverse();
}
}
void FixedUpdate()
{
if (Holded == true)
{
gameObject.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic;
gameObject.transform.position = plyr.position + offset;
gameObject.transform.rotation = plyr.rotation;
animator.SetBool("Holded", true);
animator.SetBool("isHolding", false);
}
}
void OnTriggerEnter2D(Collider2D colinfo)
{
if (colinfo.gameObject.tag == "HoldPoint")
{
FindObjectOfType<PlayerMoves>().Holdpointd();
if (this.tag == "Box")
{
FindObjectOfType<AudioManager>().Play("Boxcol");
Holded = true;
FindObjectOfType<PlayerMoves>().canthold();
}
if (this.name == "Koltuk")
{
FindObjectOfType<AudioManager>().Play("Koltukcol");
Holded = true;
FindObjectOfType<PlayerMoves>().canthold();
}
if (this.name == "Enaktar")
{
FindObjectOfType<AudioManager>().Play("Metals3");
Holded = true;
FindObjectOfType<PlayerMoves>().canthold();
}
}
}
void OnCollisionEnter2D(Collision2D colinfo)
{
// FindObjectOfType<AudioManager>().Play("Boxcol");
int Metalsound = Random.Range(1, 4);
if (this.name == "Koltuk")
{
FindObjectOfType<AudioManager>().Play("Koltukcol");
}
if (this.name == "Enaktar")
{
if (Metalsound == 1)
{
FindObjectOfType<AudioManager>().Play("Metals1");
}
if (Metalsound == 2)
{
FindObjectOfType<AudioManager>().Play("Metals2");
}
if (Metalsound == 3)
{
FindObjectOfType<AudioManager>().Play("Metals3");
}
}
if (this.tag == "Box")
{
FindObjectOfType<AudioManager>().Play("Boxcol");
}
}
}