Beispiel #1
0
    void Update()
    {
        Vector2 mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));

        m_Pitch -= mouseDelta.y * m_MouseSensitivity.y;
        m_Yaw   += mouseDelta.x * m_MouseSensitivity.x;

        m_Camera.localRotation = Quaternion.Euler(m_Pitch, m_Yaw, 0);

        if (pointingToMove)
        {
            Ray        ray = new Ray(m_PointerOriginTransform.position, m_PointerOriginTransform.forward);
            RaycastHit hit;
            float      dist = 200f;
            if (Physics.Raycast(ray, out hit, float.MaxValue, m_TowerMask))
            {
                m_SelectedTower = hit.collider.GetComponent <PlayerTower>();
                m_SelectedTower.SetSelection(true);
                dist = hit.distance;
            }
            else
            {
                m_SelectedTower?.SetSelection(false);
                m_SelectedTower = null;
            }
            Vector3 hitPosition = ray.origin + ray.direction * dist;
            m_PointerLine.SetPositions(new [] { m_PointerOriginTransform.position, hitPosition });
        }
    }
Beispiel #2
0
    void HandleMoveKeyUp()
    {
        m_PointerLine.enabled = false;

        if (m_SelectedTower != null)
        {
            m_SelectedTower.SetSelection(false);
            transform.position = m_SelectedTower.m_PlyerAnchor.position;
        }

        pointingToMove = false;
    }