コード例 #1
0
    IEnumerator Cast_Ray_Free()
    {
        yield return(null);

        // Detect the camera clicked.
        Vector3 Mouse_Pos = Input.mousePosition;
        Camera  Current_Camera;

        if (Gun_Camera && Gun_Camera.enabled && new Rect(Screen.width * Gun_Camera.rect.x, Screen.height * Gun_Camera.rect.y, Screen.width * Gun_Camera.rect.width, Screen.height * Gun_Camera.rect.height).Contains(Mouse_Pos))
        {
            Current_Camera = Gun_Camera;
        }
        else
        {
            Current_Camera = Camera.main;
        }
        // Cast Ray, and Set Target position.
        Ray        Temp_Ray = Current_Camera.ScreenPointToRay(Mouse_Pos);
        RaycastHit Temp_RaycastHit;

        if (Physics.Raycast(Temp_Ray, out Temp_RaycastHit, 1000.0f, Ray_LayerMask))
        { // Ray hits something.
            if (Temp_RaycastHit.transform.root != Root_Transform)
            {
                Target_Pos = Temp_RaycastHit.point;
            }
            else
            {
                Mouse_Pos.z = 1000.0f;
                Target_Pos  = Current_Camera.ScreenToWorldPoint(Mouse_Pos);
            }
        }
        else
        { // Ray does not hit anythig.
            Mouse_Pos.z = 1000.0f;
            Target_Pos  = Current_Camera.ScreenToWorldPoint(Mouse_Pos);
        }
    }
コード例 #2
0
    void Cast_Ray_Lock()
    {
        // Detect the camera clicked.
        Vector3 Mouse_Pos = Input.mousePosition;
        Camera  Current_Camera;

        if (Gun_Camera && Gun_Camera.enabled && new Rect(Screen.width * Gun_Camera.rect.x, Screen.height * Gun_Camera.rect.y, Screen.width * Gun_Camera.rect.width, Screen.height * Gun_Camera.rect.height).Contains(Mouse_Pos))
        {
            Current_Camera = Gun_Camera;
        }
        else
        {
            Current_Camera = Camera.main;
        }
        // Cast Ray, and Set Target position.
        Ray        Temp_Ray = Current_Camera.ScreenPointToRay(Mouse_Pos);
        RaycastHit Temp_RaycastHit;

        if (Physics.Raycast(Temp_Ray, out Temp_RaycastHit, 1000.0f, Ray_LayerMask))
        { // Ray hits something.
            if (Temp_RaycastHit.transform.root != Root_Transform)
            {
                Target_Pos = Temp_RaycastHit.point;
                if (Free_Aim_Flag == true)
                {
                    Free_Aim_Flag = false;
                }
                Set_Lock_On(Temp_RaycastHit.collider.transform);
                Target_Offset = Target_Transform.InverseTransformPoint(Temp_RaycastHit.point);
                if (Target_Transform.localScale != Vector3.one)
                { // for Armor_Collider.
                    Target_Offset.x *= Target_Transform.localScale.x;
                    Target_Offset.y *= Target_Transform.localScale.y;
                    Target_Offset.z *= Target_Transform.localScale.z;
                }
            }
        }
    }