Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using System.Collections;
public class interact_boulder : MonoBehaviour {
public GUISkin boxText;
public bool showBox;
public float GUIScreenWidth = Screen.width/2;
public float GUIScreenHeight = Screen.height/2;
public float GUIScreenToolWidth = Screen.width - 5;
public float GUIScreenToolHeight = Screen.height - 5;
void Start () {
// setting the count to 0 at start of the game
showBox = false;
}
void OnGUI() {
hasNote = player.GetComponent<interact_note>().hasNote;
GUI.skin = boxText;
if (showBox == true) {
GUI.Box(new Rect((GUIScreenWidth - 10),GUIScreenHeight,(Screen.width + 5), GUIScreenToolHeight), "I could use that note.");
}
// if hasNote is true and near the boulder object
if (hasNote == true && showBox == true ) {
if(GUI.Button(new Rect((GUIScreenWidth + 425),(GUIScreenHeight + 80),100,40), "Give the note")) {
GUI.Box(new Rect(20, 20, 400, 400), "Inventory - clear"));
// do whatever code for unlocking a thing and giving the note
// set hasNote to false
hasNote = false;
}
}
}
// exiting the collider, hide the text box
void OnTriggerExit2D(Collider2D hit)
{
print("Collider Exit");
if(hit.gameObject.tag == "interact")
{
print("Left Collider");
showBox = false;
}
}
// entering collider, show text box
void OnTriggerEnter2D(Collider2D hit)
{
print("Triggered Entered");
if(hit.gameObject.tag == "interact")
{
print("Entered Collider");
showBox = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment