//// On character switch //public void PopulateHotbarSlots() //{ // foreach (var vslot in _hotBarSlots) // { // //var slot = _hotBar.AddSlot(vslot); // if (slot != null) // { // if (!vslot.IsEmpty) // { // _inventory.AddItem(slot, vslot.Ability); // } // } // } //} public void Start() { if (gameObject == null) { return; } // TODO: Handle NPC inventory if (!_isEnabled) { return; } ResolveDependencies(); CreateVirtualSlots(); PopulateVirtualSlots(); //PopulateHotbarSlots(); _hotBar.OnAbilitySelectedHandler += OnAbilitySelected; //_hotBar.SetNumbers(); _hotBar.Select(1); }
// Update is called once per frame void Update() { if (!holding) { if (Input.GetKeyDown("1")) { ui_hotbar.Select(0); string type = "Straw"; if (items.ContainsKey(type) && items[type] > 0) { chooseObject(type, straw); } else { ui_hotbar.Select(-1); Debug.Log("You don't have the item!!!"); } holding = true; canPick = false; } else if (Input.GetKeyDown("2")) { ui_hotbar.Select(1); string type = "Wood"; if (items.ContainsKey(type) && items[type] > 0) { chooseObject(type, wood); } else { ui_hotbar.Select(-1); Debug.Log("You don't have the item!!!"); } holding = true; canPick = false; } else if (Input.GetKeyDown("3")) { ui_hotbar.Select(2); string type = "Stone"; if (items.ContainsKey(type) && items[type] > 0) { chooseObject(type, stone); } else { ui_hotbar.Select(-1); Debug.Log("You don't have the item!!!"); } holding = true; canPick = false; } else if (Input.GetKeyDown("4")) { ui_hotbar.Select(3); string type = "Iron"; if (items.ContainsKey(type) && items[type] > 0) { chooseObject(type, iron); } else { ui_hotbar.Select(-1); Debug.Log("You don't have the item!!!"); } holding = true; canPick = false; } else if (Input.GetKeyDown("5")) { ui_hotbar.Select(4); string type = "Plat_W"; if (items.ContainsKey(type) && items[type] > 0) { chooseObject(type, woodPlatform); } else { ui_hotbar.Select(-1); Debug.Log("You don't have the item!!!"); } holding = true; canPick = false; } else if (Input.GetKeyDown("6")) { ui_hotbar.Select(5); string type = "Plat_S"; if (items.ContainsKey(type) && items[type] > 0) { chooseObject(type, stonePlatform); } else { ui_hotbar.Select(-1); Debug.Log("You don't have the item!!!"); } holding = true; canPick = false; } else if (Input.GetKeyDown("7")) { ui_hotbar.Select(6); string type = "Plat_I"; if (items.ContainsKey(type) && items[type] > 0) { chooseObject(type, ironPlatform); } else { ui_hotbar.Select(-1); Debug.Log("You don't have the item!!!"); } holding = true; canPick = false; } else if (Input.GetKeyDown("8")) { ui_hotbar.Select(7); string type = "Torch"; if (items.ContainsKey(type) && items[type] > 0) { chooseObject(type, torch); } else { ui_hotbar.Select(-1); Debug.Log("You don't have the item!!!"); } holding = true; canPick = false; } } if (Input.GetKeyDown("e") && holding) { GameObject.Find("Hand").transform.DetachChildren(); item.GetComponent <Rigidbody>().isKinematic = false; item.GetComponent <CenterGravity>().enabled = true; holding = false; ui_hotbar.Select(-1); } if (Input.GetKeyDown("f") && canPick && !holding) { holding = true; } }