お世話になります。
UNITYを使用し、UIのボタンの設置と、ボタンを押した場合のスクリプト(ログに文字を出してみました)、
ランダムな数だけオブジェクトを動かすスクリプト、それら3つを作ったのですが、ボタンを押したときの動作に組み込んだところ、
エラーは出ないのですが何も起こらない状況になってしまいました。
ボタンにrigidスクリプトを関連づけて、OnClickを選んであげて、という手順を踏みました。
他には設置した画像のレイヤーがUIになっていたので、デフォルトに直したぐらいしかしておりません。
大変お手数ですが、ひとまずオブジェクトが動くようになるよう、直すべき箇所をご指摘頂けないでしょうか。
何卒よろしくお願い致します。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using System.Threading.Tasks; 5 6public class rigid : MonoBehaviour 7{ 8 int j = 0; 9 int k = 0; 10 //ボタンを押した時の処理 11 public void OnClick() 12 { 13 Vector3 targetPosition; 14 float speed = 1.0f; 15 // Use this for initialization 16 async void Start() 17 { 18 targetPosition = GameObject.Find("看板").transform.position; 19 int l = j; 20 string[] a = new string[12] { "Image", "Image (1)", "Image (2)", "Image (3)", "Image (4)", "Image (5)", "Image (6)", "Image (7)", "Image (8)", "Image (9)", "Image (10)", "Image (11)" }; 21 System.Random r1 = new System.Random(); 22 int r2 = r1.Next(0, 4);//0から2 23 for (int i = k; i <= r2 + j; i++) 24 { 25 //Cubuのオブジェクトの位置を取得 26 l = l + 1; 27 targetPosition = GameObject.Find(a[l]).transform.position; 28 await Task.Delay(1100); 29 } 30 k = j; 31 } 32 // Update is called once per frame 33 void Update() 34 { 35 float step = speed * Time.deltaTime; 36 transform.position = Vector3.MoveTowards(transform.position, targetPosition, step); 37 } 38 } 39} 40
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/15 05:19