#If Statement not working
1 messages · Page 1 of 1 (latest)
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class keys : MonoBehaviour
{
//public bool key;
public GameObject player;
public GameObject curKey;
public float distanceFromPlayer;
public static bool gotKey = false;
public GameObject canvas;
public GameObject actionText1;
public GameObject actionText2;
private bool check;
// Start is called before the first frame update
void Start()
{
//gotKey = false;
actionText1.SetActive(false);
actionText2.SetActive(false);
curKey.SetActive(true);
gotKey = false;
}
void Update()
{
distanceFromPlayer = Vector3.Distance(curKey.transform.position, player.transform.position);
}
// Update is called once per frame
void OnMouseOver()
{
distanceFromPlayer = Vector3.Distance(curKey.transform.position, player.transform.position);
if (distanceFromPlayer <= 5)
{
actionText1.SetActive(true);
actionText2.SetActive(true);
if (Input.GetButtonDown("Action"))
{
gotKey = true;
check = true;
curKey.SetActive(false);
actionText2.SetActive(false);
actionText1.SetActive(false);
}
}
if (distanceFromPlayer > 5)
{
actionText1.SetActive(false);
actionText2.SetActive(false);
}
}
void OnMouseExit()
{
actionText2.SetActive(false);
actionText1.SetActive(false);
}
public bool doesHaveKey()
{
return gotKey;
}
}