- Home /
Windows within windows
Windowception! So basically this script results in two problems, problem one the inventory right click window is within the inventory window only, it needs to be over it, and two it opens the context menu for every inventory item currently in the inventory at the same time. here's the script.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[AddComponentMenu("Camera-Control/Mouse Look")]
public class BaseGirlControl : MonoBehaviour {
// Health & Heat
public int maxhealth = 100;
public int curhealth = 100;
private float healthbarlength;
public int maxheat = 100;
public int curheat = 100;
private float heatbarlength;
public Transform GameController;
private bool rendermenu;
private string selectedItem = "";
private bool editing = false;
// movement
public float animSpeed = 1.5f;
public float speed = 10.0f;
public float RotationSpeed = 100;
private Animator anim;
// in hand items
public string pickupTag;
private Transform pickuploc;
private Transform rightPalmloc;
private bool RightHandEquip;
public bool collideweapon;
// Non in-hand items
public List<string> NearbyItems = new List<string>();
private RaycastHit hit;
private Ray ray;
private Transform ItemHolder;
public GameObject[] InventorySlots = new GameObject[6];
private Rect windowRect = new Rect(10, 300, 104, 450);
public Texture2D DefaultItemIcon;
// Use this for initialization
void Start () {
pickupTag = null;
anim = GetComponent<Animator>();
RightHandEquip = false;
collideweapon = false;
}
// Update is called once per frame
void Update () {
HandlesGUI hg = (HandlesGUI)GameController.GetComponent("HandlesGUI");
if (hg.Rendermenu == true)
{
rendermenu = true;
}
else
{
rendermenu = false;
}
AddjustCurrentHealth(0);
AddjustCurrentHeat(0);
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
anim.speed = animSpeed;
if(rendermenu == false)
{
anim.SetFloat("Speedz", v);
anim.SetFloat("Speedx", h);
transform.Rotate(0, Input.GetAxis("Mouse X"), 0 * Time.deltaTime * speed);
}
if(rendermenu == true)
{
anim.SetFloat("Speedz", 0);
anim.SetFloat("Speedx", 0);
}
// Handles weapons / In hand items
if (Input.GetButton("InteractionKey"))
{
if (collideweapon == true)
{
if (pickupTag != null)
{
pickuploc = GameObject.FindWithTag(pickupTag).transform;
pickuploc.GetComponent<WeaponControl>().ispickedup = true;
rightPalmloc = GameObject.FindWithTag("GrippingHand").transform;
pickuploc.transform.parent = rightPalmloc.transform;
RightHandEquip = true;
}
}
}
if (Input.GetButton("DropWeaponKey"))
{
if (RightHandEquip == true)
{
pickuploc = GameObject.FindWithTag(pickupTag).transform;
pickuploc.GetComponent<WeaponControl>().ispickedup = false;
RightHandEquip = false;
}
}
// Handles Clicking in gui mode to pick up items
if(rendermenu == true)
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Input.GetButtonDown("Fire1"))
{
if(Physics.Raycast(ray,out hit,20))
{
if(NearbyItems.Contains(hit.collider.tag))
{
for(int i = 0; i < InventorySlots.Length; i++)
{
if(InventorySlots[i] == null)
{
ItemControl item = (ItemControl)hit.collider.gameObject.GetComponent<ItemControl>();
InventorySlots[i] = hit.collider.gameObject;
item.ispickedup = true;
ItemHolder = GameObject.FindWithTag(item.SlotTag).transform;
InventorySlots[i].transform.parent = ItemHolder.transform;
break;
}
else
{
Debug.Log("YO INVENTORY FULL SON!");
}
}
}
}
}
}
}
void OnGUI ()
{
// Health system
if (rendermenu == true)
{
GUI.Box(new Rect(10, 10, 120, 20), "Health");
GUI.Box(new Rect(10, 30, healthbarlength, 20), curhealth + "/" + maxhealth);
GUI.Box(new Rect(10, 50, 120, 20), "Heat");
GUI.Box(new Rect(10, 70, heatbarlength, 20), curheat + "/" + maxheat);
// Calls Inventory GUI
windowRect = GUI.Window(0, windowRect, Domywindow, "Inventory" );
}
}
// Health system
public void AddjustCurrentHealth(int adj) {
curhealth += adj;
if(curhealth < 0)
curhealth = 0;
if(curhealth > maxhealth)
curhealth = maxhealth;
if(maxhealth < 1)
maxhealth = 1;
healthbarlength = (Screen.width / 2) * (curhealth / (float)maxhealth);
if(curhealth == 0)
Application.LoadLevel("MainMenu");
}
public void AddjustCurrentHeat(int adjh) {
curheat += adjh;
if(curheat < 0)
curheat = 0;
if(curheat > maxheat)
curheat = maxheat;
if(maxheat < 1)
maxheat = 1;
heatbarlength = (Screen.width / 2) * (curheat / (float)maxheat);
if(curheat == 0)
Debug.Log("Heatcold");
}
// Inventory Gui
void Domywindow(int windowId)
{
int y = 20;
GUI.DragWindow(new Rect(0,0,300,20));
for(int i = 0; i < InventorySlots.Length; i++)
{
if(InventorySlots[i] != null)
{
ItemControl v1c = (ItemControl)InventorySlots[i].gameObject.GetComponent<ItemControl>();
if(InventorySlots[i].tag != null)
{
if (GUI.Button(new Rect(20,y,64,64),v1c.icon))
{
if(Input.GetMouseButtonUp(1))
{
editing = true;
}
}
if(editing)
{
for(int x = 0; x < v1c.items.Length; x++)
{
if (GUI.Button(new Rect(0, (30 * x) + 30, 200, 30), v1c.items[i]))
{
selectedItem = v1c.items[i];
editing = false;
}
}
}
y += 70;
}
}
else
{
GUI.Button(new Rect(20,y,64,64),DefaultItemIcon);
y += 70;
}
}
}
}
and if you want to see it in game, go up to the orbs and hit escape to reach the menu mode, then click on the orbs when your near them. WebPlayer
And so you can see it without that stupid browser "FullScreen" window doesn't keep popping up heres a zip of the standalone if you want to do that. Standalone
Your answer
Follow this Question
Related Questions
Adding Item object to Inventory List 0 Answers
How to select a texture in an inventory? 0 Answers
need to shorten my code but unsure of how 3 Answers
Remove Items and Item Tooltips 0 Answers
Inventory String error 1 Answer