我在学习教程时在此脚本上遇到此错误
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public GameObject prefab;
// Instantiate the Prefab somewhere between -10.0 and 10.0 on the x-z plane
void Start()
{
Vector3 position = new Vector3(Random.Range(-10.0f, 10.0f), 0, Random.Range(-10.0f, 10.0f))
Instantiate(prefab, position, Quaternion.identity)
}
}
[记住要加上“;”在这样的行的末尾
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public GameObject prefab;
// Instantiate the Prefab somewhere between -10.0 and 10.0 on the x-z plane
void Start()
{
Vector3 position = new Vector3(Random.Range(-10.0f, 10.0f), 0, Random.Range(-10.0f, 10.0f));
Instantiate(prefab, position, Quaternion.identity);
}
}
语句必须以;
结尾
Statements (C# Programming Guide)
语句可以包含一行以结尾的代码 分号,或块中的一系列单行语句
Vector3 position = new Vector3(...); <== note the semicolon
Instantiate(...); <== note the semicolon
错误告诉您的是什么
这就是您的脚本的外观。
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public GameObject prefab;
// Instantiate the Prefab somewhere between -10.0 and 10.0 on the x-z plane
void Start()
{
Vector3 position = new Vector3(Random.Range(-10.0f, 10.0f), 0, Random.Range(-10.0f, 10.0f));
Instantiate(prefab, position, Quaternion.identity);
}
}