前提
unity始めたての初心者です。
unityで競争ゲームを制作しています。
ゴールした際に順位を表示させたいと考えています。
そこで
https://futabazemi.net/unity/goal_ranking
このサイトを参考にしてプログラミングを作成していました。
実現したいこと
- 生成したCubeではなく自分が作ったプレイヤーで反応させたい
- ゲームオブジェクトにぶつかった順で順位を表示させたい
発生している問題・エラーメッセージ
当たっても文字が表示されない
自分が作ったプレイヤーはcharactercontrollerで動かしている為
void OnControllerColliderHit(ControllerColliderHit hit)
で試したができない
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class gole : MonoBehaviour { public List<string> myList = new List<string>(); public Text firstText; public Text secondText; private int count; // Start is called before the first frame update void Start() { count = 0; } void OnControllerColliderHit(ControllerColliderHit hit) { if (hit.gameObject.tag == "Player") { myList.Add(hit.gameObject.name); hit.gameObject.SetActive(false); count++; } } void Update() { if (count == 1) { firstText.text = "1位: " + myList[0]; } else if (count == 2) { secondText.text = "2位: " + myList[1]; } } }
試したこと
先ほどのサイトの
https://futabazemi.net/unity/array_one_line
や
https://futabazemi.net/unity/object_name_array
も試したができなかった
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/01 05:23