【发布时间】:2016-11-19 09:21:09
【问题描述】:
我是一名正在从事课堂项目的新学生。在我唯一的场景中,我有 1 个脚本附加到相机上。我希望相机在第一个对象上暂停,滚动到第二个对象并暂停,然后滚动到第三个对象并暂停然后结束。将此代码放入 UPDATE 中,相机永远不会停止。在 START 中,它犹豫了大约 15 秒,然后直接到达最后一个对象,然后函数停止。注意延迟设置为 10 秒。我尝试将代码放在一个函数中并从 START 调用该函数……但没有好处。我究竟做错了什么?帮我OB1....
还有一件事... START 是播放声音的最佳场所吗?
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);
}
}
【问题讨论】:
-
您应该将代码的功能放在协程中,而不是简单的延迟。如果明天还没有回答这个问题,请仔细查看并从我的计算机而不是在我的手机上编写一些代码。另外我不建议将它放在您的更新中,因为它不需要。
-
另请注意,您可以向相机添加动画并播放该动画。
-
谢谢你....这将是一个很大的帮助。