示例#1
0
    private void Update()
    {
        Vector2 mousePos = MouseHelper.GetMouseCoords(Input.mousePosition);

        if (!GameStateManager.CanMoveTurrets)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0) && MouseHelper.ClickedInArea(mousePos, transform.position, Radius))
        {
            _isDragging = true;
            SetDisabled(false);
        }

        if (Input.GetMouseButtonUp(0) && MouseHelper.ClickedInArea(mousePos, transform.position, Radius))
        {
            _isDragging = false;
            SetDisabled(true);
        }

        if (_isDragging)
        {
            transform.position = mousePos;
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (GameStateManager.CanMoveTurrets)
        {
            _rotateLeftButton.gameObject.SetActive(true);
            _rotateRightButton.gameObject.SetActive(true);
            if (Input.GetMouseButtonDown(0))
            {
                Vector2 mousePos = MouseHelper.GetMouseCoords(Input.mousePosition);

                if (MouseHelper.ClickedInArea(mousePos, _rotateLeftButton.position, 0.5f))
                {
                    Debug.Log($"mouse clicked rotate left");
                    transform.Rotate(new Vector3(0, 0, 45));
                }

                if (MouseHelper.ClickedInArea(mousePos, _rotateRightButton.position, 0.5f))
                {
                    Debug.Log($"mouse clicked rotate right");
                    transform.Rotate(new Vector3(0, 0, -45));
                }
            }

            return;
        }
        else
        {
            _rotateLeftButton.gameObject.SetActive(false);
            _rotateRightButton.gameObject.SetActive(false);
        }

        if (GameStateManager.IsPlaying)
        {
            _reloadTimer -= Time.deltaTime;
            if (_reloadTimer <= 0)
            {
                Bullet bullet = Instantiate(BulletPrefab, transform.position, transform.rotation);
                bullet.ForwardPoint = _forwardPoint;
                bullet.Damage       = Mathf.CeilToInt(bullet.Damage * _bulletMultiplier);
                // instantiate bullet and fire in direction facing
                _reloadTimer = ReloadTimerStart;
            }
        }
    }