Esempio n. 1
0
    private void UpdateTargetMarker()
    {
        GameObject target = TargetManager.CurrentTarget;

        if (target == null || !target.activeSelf)
        {
            DeactivateChildren();
        }
        else
        {
            Vector3 headPos         = DepthRayManager.Instance.HeadPosition;
            Vector3 targetPos       = target.transform.position;
            Vector3 rayDirection    = CustomRay.RayDirection();
            Vector3 targetDirection = (targetPos - headPos).normalized;

            float angleBetween = Vector3.Angle(rayDirection, targetDirection);

            if (angleBetween > 5)
            {
                Color color = targetFinderMaterial.color;
                color.a = Mathf.Pow(Mathf.Abs(angleBetween) / 180f, 0.25f);
                targetFinderMaterial.color = color;
                ActivateChildren();
                transform.forward = targetPos - transform.position;
            }
            else
            {
                DeactivateChildren();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        Ray ray = gameObject.GetComponent <Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));       //메인 카메라
        //Debug.Log("ray:" + ray);
        Camera cam = gameObject.GetComponent <Camera>();
        // Debug.Log((cam.transform.rotation * Vector3.zero * cam.nearClipPlane) + cam.transform.position);

        /*
         * 1. Ray의 첫번째 값 : 카메라 Viewport의 시작지점 (카메라 앞의 '사각형') => 카메라 시작 좌표 * 카메라 로테이션 회전 + near값 만큼 전진.
         * 2. Ray의 두번째 값 : 1번 값에 수직인 벡터
         *
         */

        CustomRay m_ray = CameraViewToRay(cam);
        // Debug.Log(m_ray.Direction);

        RaycastHit hit;         //얘는 걍 있는거 쓰기.

        // if (Physics.Raycast(ray, out hit, Reach)) {
        //      Debug.Log("Ray hit : " + hit.collider.tag);
        // }

        if (isOn == true)
        {
            Debug.DrawRay(m_ray.Origin, m_ray.Direction * Reach, debugRayColor);
        }
    }
    public bool Raycast(CustomRay ray, out CustomHitInfo hitInfo, int maxDistance)
    {
        hitInfo = new CustomHitInfo();
        //  TODO: Write raycast function

        /*
         * for (int i = 0; i < 3; ++i)
         * {
         *  float invD = 1/ray.m_direction[i];
         *  float t0 = (i - ray.m_origin[i])*invD;
         * }
         */
        return(true);
    }
 private void Awake()
 {
     Instance = this;
 }