-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlueFunction.cs
More file actions
59 lines (51 loc) · 1.72 KB
/
GlueFunction.cs
File metadata and controls
59 lines (51 loc) · 1.72 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GlueFunction : MonoBehaviour {
private Collider obj1;
private Collider obj2;
private int counter = 0;
private Collider obj2Collider;
private bool readRadius;
public bool glue;
private void OnTriggerEnter(Collider other)
{
if (counter == 0 && other.gameObject.layer == LayerMask.NameToLayer("GraspableObjects"))
{
obj1 = other;
counter++;
Debug.Log("Object 1 assigned");
readRadius = true;
}
else if (counter == 1 && other.gameObject.layer == LayerMask.NameToLayer("GraspableObjects"))
{
obj2 = other;
counter++;
Debug.Log("Object 2 assigned");
counter = 0;
Debug.Log("Counter reset");
}
}
private void Update()
{
if (readRadius)
{
float radius = obj1.transform.localScale.magnitude;
if (obj2.enabled)
{
glue = true;
GlueObjects(obj1, obj2, radius);
readRadius = false;
}
}
}
private void GlueObjects(Collider obj1, Collider obj2, float radius)
{
obj2.transform.parent = obj1.transform;
obj2.attachedRigidbody.useGravity = false;
obj2.attachedRigidbody.isKinematic = true;
//obj2.enabled = false;
//obj2.transform.position = new Vector3(obj1.transform.position.x,obj1.transform.position.y, obj1.transform.position.z + radius);
//obj2.transform.localRotation = Quaternion.Euler(new Vector3(0.0f, 45.0f, 45.0f));
}
}