1
0
Fork 0

add trigger to door prefab

This commit is contained in:
Jan 2018-04-21 18:21:31 +02:00
parent f50398e44b
commit 7b684c1800
2 changed files with 18 additions and 8 deletions

View file

@ -23,7 +23,7 @@ GameObject:
- component: {fileID: 61859685447846418}
- component: {fileID: 61191558022818200}
m_Layer: 0
m_Name: UpperDoor
m_Name: Door
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -36,7 +36,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1046373619020340}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 9.06, z: 0}
m_LocalPosition: {x: 0, y: 9, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -54,7 +54,7 @@ BoxCollider2D:
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.3731112, y: 0}
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
@ -65,7 +65,7 @@ BoxCollider2D:
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 3.025469, y: 1}
m_Size: {x: 3, y: 1}
m_EdgeRadius: 0
--- !u!61 &61859685447846418
BoxCollider2D:
@ -79,7 +79,7 @@ BoxCollider2D:
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.37311125, y: 0}
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
@ -88,9 +88,9 @@ BoxCollider2D:
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
m_AutoTiling: 1
serializedVersion: 2
m_Size: {x: 3.0254688, y: 1}
m_Size: {x: 3, y: 1}
m_EdgeRadius: 0
--- !u!114 &114712631247209960
MonoBehaviour:

View file

@ -6,9 +6,17 @@ public class Door : MonoBehaviour {
private bool locked = false;
BoxCollider2D boundingBox;
BoxCollider2D triggerBox;
// Use this for initialization
void Start () {
boundingBox = GetComponent<BoxCollider2D>();
BoxCollider2D[] colliders = GetComponents<BoxCollider2D>();
foreach (BoxCollider2D collider in colliders) {
if (collider.isTrigger) {
triggerBox = collider;
} else {
boundingBox = collider;
}
}
Unlock();
}
@ -16,12 +24,14 @@ public class Door : MonoBehaviour {
{
locked = true;
boundingBox.enabled = true;
triggerBox.enabled = false;
}
public void Unlock()
{
locked = false;
boundingBox.enabled = false;
triggerBox.enabled = true;
}
public bool IsLocked()