/**
     * Function to assign a sprite to a hotbar slot
     * @param item - the item being moved
     * @param swapItem - item in the slot the first item is being moved to
     * @param origPos - Original position of the item being moved
     */
    private void AssignHotbarSprite(GameObject item, GameObject hotbarSlot)
    {
        //Get the image and transform of the moving item
        Image itemImage = item.GetComponent <Image>();

        //Get the image and transform of the hotbar item
        Image hotbarImage = hotbarSlot.GetComponent <Image>();

        //Change the hotbar sprite & match its transform to that of the item
        //(to ensure appropriate scaling)
        hotbarImage.sprite = itemImage.sprite;

        //Make the hotbar icon visible
        Color hotbarColor = hotbarImage.color;

        hotbarColor.a     = 1;
        hotbarImage.color = hotbarColor;

        //Update the hotbar data in the Held_Items script
        Item_Icon_Data _itemDataScript   = item.GetComponent <Item_Icon_Data>();
        Hotbar_Data    _hotbarDataScript = hotbarSlot.GetComponent <Hotbar_Data>();
        Held_Items     _heldItemScript   = _player.GetComponent <Held_Items>();

        int _itemIndex   = _itemDataScript.GetInventoryIndex();
        int _hotbarIndex = _hotbarDataScript.GetSlotIndex();

        _heldItemScript.UpdateHotbar(_hotbarIndex, _itemIndex);
    }
    private void Start()
    {
        _player          = GameObject.FindGameObjectWithTag("Player");
        _helditemsScript = _player.GetComponent <Held_Items>();

        _camera = GameObject.FindGameObjectWithTag("MainCamera");

        _playerMouseScript = _player.GetComponent <Mouse_Look>();
        _cameraMouseScript = _camera.GetComponent <Mouse_Look>();
        _controlScript     = _player.GetComponent <Player_Controller_v1>();

        if (inventory == null)
        {
            inventory = GameObject.FindGameObjectWithTag("Inventory");
            inventory.SetActive(false);
        }
    }
Пример #3
0
 private void Start()
 {
     player         = GameObject.FindGameObjectWithTag("Player");
     heldItemScript = player.GetComponent <Held_Items>();
 }