-
Notifications
You must be signed in to change notification settings - Fork 0
/
Detachable.cs
44 lines (37 loc) · 1.2 KB
/
Detachable.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Detachable : MonoBehaviour
{
private MeshRenderer meshRenderer;
private GameObject bodyPartCopy;
private Rigidbody rigidbodyCopy;
private void Start()
{
try
{
meshRenderer = GetComponent<MeshRenderer>();
Debug.Log("transfer child out of bound of array. can not accessable it...!!!");
bodyPartCopy = transform.GetChild(1).gameObject;
rigidbodyCopy = bodyPartCopy.GetComponent<Rigidbody>();
bodyPartCopy.SetActive(false);
}
catch(System.Exception e) {
Debug.Log("detachable class can not solved this array "+e.Message+" ...!!!");
}
finally
{
//none
}
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("pickup"))
{
meshRenderer.enabled = false;
bodyPartCopy.SetActive(true);
var random = UnityEngine.Random.Range(-10 , 10);
rigidbodyCopy.AddTorque(new Vector3(random, random, random), ForceMode.Impulse);
}
}
}