First off i have a window which has 6 buttons, i want this to be my weapon cache. How do i go about setting each button to have a different weapon, and when clicked it will allow me in game to drag the current weapon onto a part of the map. Basically what i want is within many tower defence games where you select a weapon then place it on the map(minus the hud and buttons).
my code so far(only shows buttons and window which can be opened and closed):
using UnityEngine;
using System.Collections;
public class MyGUI : MonoBehaviour {
//public GUISkin mySkin;
public float buttonWidth = 5.0f;
public float buttonHeight = 5.0f;
/*****************************************/
/* Weapon Cache window */
/***********************/
private bool displayWeaponCache = true;
private const int WEAPON_CACHE_ID = 1;
private Rect weaponWindowRect = new Rect(525.0f, 5.0f, 50.0f, 400.0f);
private int weaponCols = 1;
private int weaponRows = 9;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
if (displayWeaponCache)
{
weaponWindowRect = GUI.Window(WEAPON_CACHE_ID, weaponWindowRect,
WeaponCacheWindow, "");
}
if(GUI.Button(new Rect (575.0f, 5.0f, 25.0f, 25.0f),"X"))
{
displayWeaponCache= !displayWeaponCache;
}
}
public void WeaponCacheWindow(int winID)
{
for (int y = 0; y < weaponRows; y++)
{
for (int x = 0; x < weaponCols; x++)
{
GUI.Button(new Rect(5 + (x * buttonWidth),
10 + (y * buttonHeight),buttonWidth, buttonHeight),
(x + y * weaponCols).ToString());
}
}
}
}
i also know this is a lot of work but im, only looking for tips and to be lead in the correct direction thanks much appreciated :D