I have a problem with my script, the problem is it makes me repeatedly Probelm to accessing a function:
I have a Key and a Door Object.
When you take the key of the value to be implemented in the Door.cs.
KeyObject.cs
using UnityEngine;
using System.Collections;
public class KeyObject : MonoBehaviour {
Door door;
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Player"))
{
door.GiveKey();
Destroy(gameObject);
}
}
}
Door.cs
using UnityEngine;
using System.Collections;
public class Door : MonoBehaviour
{
private bool Keys = false;
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Player"))
{
if (Keys == false)
{
Debug.Log("Access DENIED");
}
else
{
Destroy(gameObject);
}
}
}
public void GiveKey()
{
Keys = true;
}
}
greeting
D. Elskamp