私はクラスのプロジェクトに取り組んでいる新しい学生です。私は唯一の場面でカメラに1つのスクリプトを添付しています。カメラが第1オブジェクト上で一時停止し、第2オブジェクトにスクロールして一時停止し、第3オブジェクトにスクロールして一時停止して終了します。このコードをUPDATEに置くと、カメラは決して停止しません。ここでSTARTでは15秒くらい躊躇してから最後のオブジェクトに行くと機能が停止します。遅延は10秒に設定されていることに注意してください。関数にコードを入れてSTARTから関数を呼び出そうとしましたが、うまくいきませんでした。私は間違って何をしていますか? HELP ME OB1 ....x軸上の3つのオブジェクトを一時停止するにはどうすればよいですか?
もう1つ...スタートは音を鳴らすのに最適な場所ですか?
using UnityEngine;
using System.Collections;
// I want the camera to pause over the 1st object, scroll to the 2nd object and pause
// then scroll to the 3rd object and pause then end. Putting this code in the UPDATE
// the camera never stops. Here in the START, it hesitates around 15 sec and then it
// goes right to the last object, then the function stops. Note the delay set for 10
// seconds.
public class CameraControl : MonoBehaviour
{
public float speed; // How fast to move the camera
public int moves; // How many moves to make
public float MyWait; // How long to pause over object
// Use this for initialization
void Start()
{
StartCoroutine(MyDelay());
for (int y = 1; y <= 2; y++) // go to the next two objects
{
for (int i = 1; i <= moves; i++) // Move the camera to the next position
{
Camera.main.transform.Translate(new Vector3(1.0f, 0.0f, 0.0f) * speed * Time.deltaTime);
Debug.LogFormat("moves = {0} ", i);
}
StartCoroutine(MyDelay());
}
}
IEnumerator MyDelay()
{
yield return new WaitForSeconds(10.0f);
}
}
単純な遅延ではなく、コードの機能をコルーチンに配置する必要があります。この質問が明日までに返答されない場合は、私の電話ではなく、私のコンピュータからコードを書いてみてください。また、それはあなたのアップデートに配置することをお勧めしません。 – Alox
また、カメラにアニメーションを追加してそのアニメーションを再生することもできます。 – Alox
ありがとうございました....それは大きな助けになるでしょう。 – BillB