hello I have a door on other object When user hit “F” door should open and it is opening but when i use reference outside the beginning functions(awake or start) it dosent work how can I fix it ?
Door’s name is door123
CODE :
Dooropen.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dooropen : MonoBehaviour {
bool yesintrigger;
door123script d123;
private void Awake()
{
d123 = GameObject.Find("door123").GetComponent<door123script>();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
yesintrigger = true;
}
}
private void Update()
{
if (yesintrigger)
{
if (Input.GetKeyDown(KeyCode.F))
{
d123.open = true;
}
}
}
}
door123script.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class door123script : MonoBehaviour {
public bool open;
private void Update()
{
if(open)
{
gameObject.SetActive(false);
}
}
}