Exemple #1
0
        void Update()
        {
            if (_currentItem != null)
            {
                Ray  ray        = _camera.ScreenPointToRay(Input.mousePosition);
                bool isOnGround = false;

                if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity))
                {
                    _ghostRenderer.enabled        = true;
                    _ghostItem.transform.position = hit.point;
                    isOnGround = true;
                }
                else
                {
                    _ghostRenderer.enabled = false;
                }

                if (isOnGround && Input.GetKeyDown(KeyCode.Mouse0))
                {
                    GameObject instance = Instantiate(
                        _currentItem,
                        _ghostItem.transform.position,
                        _ghostItem.transform.rotation
                        );

                    OnItemPlaced?.Invoke(instance);
                }
            }
Exemple #2
0
    private void Buy(Item item)
    {
        GameManager.Instance.BuyItem(item);
        Item itemInstance = Instantiate(item, _ghostItemGameObject.transform.position, _ghostItemGameObject.transform.rotation);

        itemInstance.Initialize();

        itemInstance.Animator.SetTrigger("Spawn");
        OnItemPlaced?.Invoke(itemInstance);
    }