top of page

RayCastを飛ばす.非貫通(タグ)

    void Ray(){
        
        // outパラメータ用に、Rayのヒット情報を取得するための変数を用意
        RaycastHit hit;

        var isHit = Physics.Raycast (transform.position, transform.forward, out hit, 100);

        if (isHit) {
            
            Debug.DrawRay (transform.position, transform.forward * hit.distance);

            // Rayがhitしたオブジェクトのタグを取得
            string hitName = hit.collider.tag;

            //ヒットしたオブジェクトのタグがTESTなら
            if (hitName.Equals("TEST")) 
            {
            }


            //TEST以外の名前なら
            else 
            {
            }

        }
        else

        {
            Debug.DrawRay (transform.position, transform.forward * 100);
        }

    }        
 

bottom of page