This commit is contained in:
Vova
2023-06-22 10:42:56 +03:00
parent 49da969226
commit 359cf2000a
7 changed files with 55 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorController : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
//if player have key, door will open
//else player can't pass
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3ead8e41e973dd43b93a8638ea30a36
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
namespace Assets.Scripts
{
public interface IDoor
{
void OpenDoor();
void ToggleDoor();
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 62a1e4daba023c94f9fe4c576570cbf4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+10
View File
@@ -17,6 +17,7 @@ public class PlayerController : MonoBehaviour
private BoxCollider2D _boxCollider;
private bool _isFall;
private bool _facingRight = true;
private bool _haveKey = false;
void Start()
@@ -106,4 +107,13 @@ public class PlayerController : MonoBehaviour
_facingRight = !_facingRight;
}
private void OnTriggerEnter2D(Collider2D collision)
{
var door = collision.GetComponent<DoorController>();
if (door != null)
{
door.OpenDoor();
}
}
}