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!
1 Answer
1So 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;
}
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 instead. If you have any errors in the console, let us know of those.
– Statement