-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttracktor.cs
More file actions
53 lines (47 loc) · 1.66 KB
/
Attracktor.cs
File metadata and controls
53 lines (47 loc) · 1.66 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Collider))]
public class Attracktor : MonoBehaviour {
public float onPoint = 0.01f;
public Vector3 offset;
private bool attracktionComplete = false;
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("AddOn"))
{
other.collider.attachedRigidbody.isKinematic = true;
other.collider.attachedRigidbody.useGravity = false;
other.collider.enabled = false;
other.collider.transform.parent = transform;
}
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag("AddOn") && !attracktionComplete)
{
// Start attract coroutine
StartCoroutine(Attract(other));
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("AddOn"))
{
other.attachedRigidbody.isKinematic = false;
other.attachedRigidbody.useGravity = true;
other.transform.parent = null;
other.enabled = true;
}
}
IEnumerator Attract(Collider other)
{
other.gameObject.transform.position = Vector3.MoveTowards(other.gameObject.transform.position,transform.position, 0.0075f);
//float distance = Vector3.Distance(other.gameObject.transform.position, transform.position + offset);
//if (distance < onPoint)
//{
// attracktionComplete = true;
//}
yield return null;
}
}