示例#1
0
    void ClickToSpawn()
    {
        if (BattleManager.IsPause)
        {
            return;
        }
        if (!CanShoot)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            //Set up the new Pointer Event
            m_PointerEventData = new PointerEventData(m_EventSystem);
            //Set the Pointer Event Position to that of the mouse position
            m_PointerEventData.position = Input.mousePosition;
            //Create a list of Raycast Results
            List <RaycastResult> results = new List <RaycastResult>();
            //Raycast using the Graphics Raycaster and mouse click position
            m_Raycaster.Raycast(m_PointerEventData, results);
            //For every result returned, output the name of the GameObject on the Canvas hit by the Ray
            foreach (RaycastResult result in results)
            {
                if (result.gameObject.tag == "UI")
                {
                    return;
                }
            }

            Ray ray = MyCamera.ScreenPointToRay(Input.mousePosition);
            StartPos = ray.origin + (ray.direction * MyCamera.transform.position.z * -1);


            Go_EndPos.transform.position   = StartPos;
            Go_StartPos.transform.position = StartPos;
            IsPress   = true;
            DragTimer = 0;
        }
        if (Input.GetMouseButton(0))
        {
            if (!IsPress)
            {
                return;
            }
            DragTimerFnc();
            if (IsDrag)
            {
                Ray ray = MyCamera.ScreenPointToRay(Input.mousePosition);
                CurPos = ray.origin + (ray.direction * MyCamera.transform.position.z * -1);
                Go_EndPos.transform.position = CurPos;;
                float angle = MyMath.GetAngerFormTowPoint2D(CurPos, StartPos);
                BattleCanvas.PlayerBowDraw(180 - angle, GetDragProportion());
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (IsPress)
            {
                IsPress = false;
            }
            else
            {
                return;
            }

            if (!IsDrag)
            {
                return;
            }
            else
            {
                IsDrag = false;
            }
            Go_StartPos.SetActive(false);
            Go_EndPos.SetActive(false);
            Ray ray = MyCamera.ScreenPointToRay(Input.mousePosition);
            CurPos = ray.origin + (ray.direction * MyCamera.transform.position.z * -1);
            EndPos = CurPos;
            Shoot();
        }
    }