-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tag (Documentation)
83 lines (71 loc) · 2.3 KB
/
Tag (Documentation)
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
/*
Note: 1. If gameobject have layer and tag attached same time. tag may not work sometime.
2. You should not set a tag from the Awake() or OnValidate() method.
3. Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody.
If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.
4. To use the following code sample, create a primitive GameObject, and attach a Collider and Rigidbody component to it.
Enable Collider.isTrigger and Rigidbody.isKinematic. When the primitive collides, OnTriggerEnter gets called.
*/
void OnTriggerEnter(Collider other)
{
//if (other.tag == "Player")
//Or
if (other.gameObject.tag == "Player")
{
Debug.Log("Player Enter");
}
else
{
Debug.Log("Other Enter");
}
}
//OR
void OnTriggerEnter(Collider other)
{
//if (other.name == "Player Name")
//Or
if (other.gameObject.name == "Player Name")
{
Debug.Log("Player Enter");
}
else
{
Debug.Log("Other Enter");
}
}
//OR
void OnTriggerEnter(Collider other)
{
if(other.gameObject.layer == LayerMask.NameToLayer("Layer Name"))
{
Debug.Log("Player Enter");
}
else
{
Debug.Log("Other Enter");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log("Player Inside Staying Now");
}
else
{
Debug.Log("Other Inside Staying Now");
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log("Player exit");
}
else
{
Debug.Log("Other Exit");
}
}