- Home /
GUI text from destroyed object.
Hello. I have an inventory and i add items into it by picking up items from floor (Collision) and then this object is destroyed. I want to show GUI information for example "Coin taken" while i add this item to inventory. I already tried making other script that handle GUI and the item script just send static information to information showing script but it dont work as well. Propobly this is a easy taks but i dont have such knowlage. I belive i rewiewd my problem clearly. Sorry for my english and thank You for Your answers. Cheers!
I don't mean to be rude, but try to accept my apologies if it still comes across as it.
but it dont work as well [...] I belive i rewiewd my problem clearly
What is "it"? Can you show us some example code? Explain what you wanted to happen. Explain what happens ins$$anonymous$$d. If you have any errors in the console, let us know of those.
Answer by A13n · Dec 13, 2013 at 10:22 PM
So I have a code that handles item looting and destroy it after pick up, so I want it to also show infomation on GUI that item was picked up. Here is the script: enter code hereimport System.Collections.Generic;
var loot : ItemClass[];
var Inventory : Inventory;
var info : int = 0;
var buttonTransform : Transform;
var distToTake : float = 6;
@HideInInspector
var playerTransform : Transform;
@HideInInspector
var cameraTransform : Transform;
function Start ()
{
Inventory = GetComponent("Inventory") as Inventory;
}
function Awake ()
{
playerTransform = GameObject.FindWithTag("Player").transform;
cameraTransform = GameObject.FindWithTag("MainCamera").transform;
}
function Update ()
{
var angle : float = Vector3.Angle(buttonTransform.position - cameraTransform.position, buttonTransform.position + (cameraTransform.right * buttonTransform.localScale.magnitude) - cameraTransform.position);
if (Vector3.Distance(playerTransform.position,buttonTransform.position) <= distToTake)
if (Vector3.Angle(buttonTransform.position - cameraTransform.position, cameraTransform.forward) <= angle)
if (Input.GetButtonDown("Use"))
{
Debug.Log("Use");
if(Inventory.MainInventory.Count == 0)
{
info = 3;
}
else
for(var x = 0; x < Inventory.MainInventory.Count; x++)
{
if(Inventory.MainInventory[x].id == 1)
{
info = 4;
giveloot();
renderer.enabled = false;
Destroy(gameObject,5);
}
if(x == 0)
{
info = 3;
}
}
}
}
function giveloot()
{
for(var x = 0; x < loot.length; x++)
{
Inventory.MainInventory.Add(loot[x]);
}
}
function OnGUI()
{
if(info == 1)
{
GUILayout.BeginArea(Rect(Screen.width/2 - 250, Screen.height/2, 500, 500));
GUILayout.BeginHorizontal();
GUILayout.Box("You need a bronze set of keys.");
GUILayout.EndHorizontal();
GUILayout.EndArea();
czekaj();
}
if(info == 2)
{
GUILayout.BeginArea(Rect(Screen.width/2 - 250, Screen.height/2, 500, 500));
GUILayout.BeginHorizontal();
GUILayout.Box("Well done!");
GUILayout.EndHorizontal();
GUILayout.EndArea();
czekaj();
}
if(info == 3)
{
GUILayout.BeginArea(Rect(Screen.width/2 - 250, Screen.height/2, 500, 500));
GUILayout.BeginHorizontal();
GUILayout.Box("You can't reach the keys, they are too far. You need something long to grab them.");
GUILayout.EndHorizontal();
GUILayout.EndArea();
czekaj();
}
if(info == 4)
{
GUILayout.BeginArea(Rect(Screen.width/2 - 250, Screen.height/2, 500, 500));
GUILayout.BeginHorizontal();
GUILayout.Box("Bronze Key Set taken.");
GUILayout.EndHorizontal();
GUILayout.EndArea();
czekaj();
}
if(info == 5)
{
GUILayout.BeginArea(Rect(Screen.width/2 - 250, Screen.height/2, 500, 500));
GUILayout.BeginHorizontal();
GUILayout.Box("Metal bar taken.");
GUILayout.EndHorizontal();
GUILayout.EndArea();
czekaj();
}
}
function czekaj()
{
yield WaitForSeconds (5);
info = 0;
}
Your answer

Follow this Question
Related Questions
Coding Gui Text To Perform After GameObject Destroy? 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Create a text box that appears at start of game, then disappears with any player input 2 Answers
Instantiated GameObject being deleted when destroying original 1 Answer
Destroy script still works on 2 Answers