void Update()
    {
        _Amount.text = _InventoryScript.StoneAmount.ToString();

        _Rot.x = _ShootPos.transform.rotation.x;
        _Rot.y = _ShootPos.transform.rotation.y;
        _Rot.z = _ShootPos.transform.rotation.z;
        _Rot   = Vector3.forward;

        RaycastHit hit;

        if (Physics.Raycast(_ShootPos.transform.position, _ShootPos.transform.TransformDirection(_Rot), out hit, 5))
        {
            for (int i = 0; i < _Buttons.Length; i++)
            {
                if (hit.transform.gameObject == _Buttons[i].gameObject)
                {
                    _Buttons[i].interactable = true;
                    if (_InventoryScript.StoneAmount >= _Cost[i])
                    {
                        if (Input.GetKeyDown(KeyCode.E))
                        {
                            _InventoryScript.StoneAmount -= _Cost[i];
                            _InventorySlotScript.AddItemToInventory(1, _Objects[i], _ObjectsBlueprint[i], _Sprite[i]);
                            if (i == 0)
                            {
                                _Cost[i] = Mathf.RoundToInt(_Cost[i] * 1.5f);
                            }
                            if (i == 1)
                            {
                                _Cost[i] = Mathf.RoundToInt(_Cost[i] * 1.8f);
                            }
                            for (int o = 0; o < _Cost.Length; o++)
                            {
                                Mathf.RoundToInt(_Cost[o]);
                            }
                        }
                    }
                }
                else
                {
                    _Buttons[i].interactable = false;
                }
            }
        }

        for (int i = 0; i < _Cost.Length; i++)
        {
            _CostText[i].text = _Cost[i].ToString();
        }
    }
Пример #2
0
    void Update()
    {
        _PrefabObj          = _SlotsScript._InventorySlotObj[_SlotsScript._CurrentSlotID];
        _PrefabObjBluePrint = _SlotsScript._InventorySlotBlueprint[_SlotsScript._CurrentSlotID];

        _Rot.x = _ShootPos.transform.rotation.x;
        _Rot.y = _ShootPos.transform.rotation.y;
        _Rot.z = _ShootPos.transform.rotation.z;
        _Rot   = Vector3.forward;

        RaycastHit hit;

        if (_PrefabObj != null)
        {
            //Miners
            if (Physics.Raycast(_ShootPos.transform.position, _ShootPos.transform.TransformDirection(_Rot), out hit, _Range_Miners))
            {
                Debug.DrawRay(_ShootPos.transform.position, _ShootPos.transform.TransformDirection(_Rot) * hit.distance, Color.black);
                if (_SlotsScript._InventorySlotObj[_SlotsScript._CurrentSlotID].tag == "Machine")
                {
                    if (hit.transform.gameObject.tag == "Resources")
                    {
                        if (_PrefabExample == null)
                        {
                            _PrefabExample = Instantiate(_PrefabObjBluePrint, _ShootPos.transform.position, Quaternion.identity);
                        }
                        else
                        {
                            _PrefabExample.transform.position = hit.point;
                            Vector3 rot2 = new Vector3(-90 + _RotationObj.transform.rotation.eulerAngles.x, _RotationObj.transform.rotation.eulerAngles.y, 0);
                            _PrefabExample.transform.eulerAngles = rot2;
                        }
                    }
                    else
                    {
                        Destroy(_PrefabExample);
                    }
                }
            }
            //Turrets
            if (Physics.Raycast(_ShootPos.transform.position, _ShootPos.transform.TransformDirection(_Rot), out hit, _Range_Turret))
            {
                if (_SlotsScript._InventorySlotObj[_SlotsScript._CurrentSlotID].tag == "Turret")
                {
                    if (hit.transform.gameObject.tag == "Ground")
                    {
                        if (_PrefabExample == null)
                        {
                            _PrefabExample = Instantiate(_PrefabObjBluePrint, _ShootPos.transform.position, Quaternion.identity);
                        }
                        else
                        {
                            _PrefabExample.transform.position = hit.point;
                        }
                    }
                    else
                    {
                        Destroy(_PrefabExample);
                    }
                }
            }

            if (Input.GetMouseButtonDown(0))
            {
                //Miners
                if (Physics.Raycast(_ShootPos.transform.position, _ShootPos.transform.TransformDirection(_Rot), out hit, _Range_Miners))
                {
                    if (_SlotsScript._InventorySlotObj[_SlotsScript._CurrentSlotID].tag == "Machine")
                    {
                        if (hit.transform.gameObject.tag == "Resources")
                        {
                            Vector3 targetPosition = hit.point;

                            GameObject otherObj       = Instantiate(_PrefabObj, _ShootPos.transform.position, Quaternion.identity);
                            Resources  resourceScript = hit.transform.gameObject.GetComponent <Resources>();
                            Machine    machineScript  = otherObj.GetComponent <Machine>();
                            machineScript._Resource     = resourceScript;
                            otherObj.transform.position = hit.point;

                            Vector3 rot2 = new Vector3(-90 + _RotationObj.transform.rotation.eulerAngles.x, _RotationObj.transform.rotation.eulerAngles.y, 0);//m_RotationObj.transform.rotation.eulerAngles.y);

                            otherObj.transform.eulerAngles = rot2;

                            _SlotsScript._ObjectAmount[_SlotsScript._CurrentSlotID] -= 1;
                            otherObj = null;
                        }
                    }
                }
                //Turret
                if (Physics.Raycast(_ShootPos.transform.position, _ShootPos.transform.TransformDirection(_Rot), out hit, _Range_Turret))
                {
                    if (_SlotsScript._InventorySlotObj[_SlotsScript._CurrentSlotID].tag == "Turret")
                    {
                        if (hit.transform.gameObject.tag == "Ground")
                        {
                            Vector3 targetPosition = hit.point;

                            GameObject otherObj = Instantiate(_PrefabObj, _ShootPos.transform.position, Quaternion.identity);
                            otherObj.transform.position = hit.point;

                            _SlotsScript._ObjectAmount[_SlotsScript._CurrentSlotID] -= 1;
                            otherObj = null;
                        }
                    }
                }
            }
        }
        else
        {
            _PrefabObj = null;
            Destroy(_PrefabExample);
            _PrefabObjBluePrint = null;
        }

        if (Physics.Raycast(_ShootPos.transform.position, _ShootPos.transform.TransformDirection(_Rot), out hit, 3))
        {
            Machine m_MachineScript = null;
            if (hit.transform.gameObject.tag == "Machine")
            {
                m_MachineScript = hit.transform.gameObject.GetComponent <Machine>();
                if (!hit.transform.gameObject.GetComponent <Rigidbody>().isKinematic)
                {
                    _InfoText.text = "E To Pick Up";
                    if (Input.GetKeyDown(KeyCode.E))
                    {
                        _SlotsScript.AddItemToInventory(1, m_MachineScript._Obj, m_MachineScript._ObjBlueprint, m_MachineScript._ObjSprite);
                        Destroy(hit.transform.gameObject);
                    }
                }
            }
        }
        else
        {
            _InfoText.text = "";
        }
    }