Help us understand the problem. What is going on with this article?

Rayを飛ばして当たったオブジェクトの情報を得る方法

More than 1 year has passed since last update.
void RayTest()
    {
        //Rayの作成       ↓Rayを飛ばす原点   ↓Rayを飛ばす方向
        Ray ray = new Ray (transform.position, new Vector3 (0, -1, 0));

        //Rayが当たったオブジェクトの情報を入れる箱
        RaycastHit hit;

        //Rayの飛ばせる距離
        int distance = 10;

        //Rayの可視化    ↓Rayの原点    ↓Rayの方向         ↓Rayの色
        Debug.DrawLine (ray.origin, ray.direction * distance, Color.red);

        //もしRayにオブジェクトが衝突したら
        //                  ↓Ray  ↓Rayが当たったオブジェクト ↓距離
        if (Physics.Raycast(ray,out hit,distance))
        {
              //Rayが当たったオブジェクトのtagがPlayerだったら
                if (hit.collider.tag == "Player")
                Debug.Log ("RayがPlayerに当たった");
        }
    }
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away