3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unity オブジェクト間の距離を求める

Last updated at Posted at 2020-10-19

オブジェクト間の距離を求めるにはVector3.Distanceを使う。(今日知った泣)
スクリーンショット 2020-10-19 21.10.19.png

using UnityEngine;
using UnityEngine.UI;

public class DistanceController : MonoBehaviour
{
    public GameObject MajorObj;
    public GameObject Surface;
    public Text MajorText;

    // Update is called once per frame
    void Update()
    {
        Vector3 Apos = MajorObj.transform.position;
        Vector3 Bpos = Surface.transform.position;
        float dis = Vector3.Distance(Apos, Bpos);
        MajorText.text = "現在の距離: " + dis+ "m";
    }
}
3
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?