Skip to content

Instantly share code, notes, and snippets.

@adash333
Created August 18, 2019 09:47
Show Gist options
  • Save adash333/7c5c2b1e963d08a56c8e26b5c569369b to your computer and use it in GitHub Desktop.
Save adash333/7c5c2b1e963d08a56c8e26b5c569369b to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; // UI部品を使用するために必要
public class GameDirector : MonoBehaviour {
GameObject car;
GameObject flag;
GameObject distance;
// Use this for initialization
void Start () {
this.car = GameObject.Find ("car"); // このように記載することでプロジェクト内のcarオブジェクトを見つけることができる
this.flag = GameObject.Find("flag");
this.distance = GameObject.Find("Distance");
}
// Update is called once per frame
void Update () {
float length = this.flag.transform.position.x - this.car.transform.position.x;
this.distance.GetComponent<Text> ().text = "ゴールまで" + length.ToString ("F2") + "m";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment