【发布时间】:2016-08-19 17:21:30
【问题描述】:
我最近一直在关注 youtube 上“Brackeys”的塔防游戏教程,我逐字逐句地按照它进行操作,但有一个错误(在下面的照片中)不会让我的敌人预制件移动在场景中。预制件都在产卵,但卡在一个地方。 任何帮助将不胜感激
谢谢,米奇
using UnityEngine;
public class Enemy : MonoBehaviour
{
public float speed = 10f;
private Transform target;
private int wavePointIndex = 0;
// Use this for initialization
void Start()
{
// An error pops up on the first frame for this line of code below
target = Waypoints.points[0];
}
// Update is called once per frame
void Update ()
{
// This is the main source of the error below.
Vector3 dir = target.position - transform.position;
transform.Translate (dir.normalized * speed * Time.deltaTime, Space.World);
if (Vector3.Distance (transform.position, target.position) <= 0.4f)
{
GetNextWayPoint ();
}
}
void GetNextWayPoint()
{
if (wavePointIndex >= Waypoints.points.Length - 1)
{
Destroy (gameObject);
return;
}
wavePointIndex++;
target = Waypoints.points[wavePointIndex];
}
}
error description in unity Enemy prefab that has script on it
【问题讨论】: