脚本错误:';'预期。统一错误

问题描述 投票:-2回答:3

我在学习教程时在此脚本上遇到此错误

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)
    }
}
c# unity3d
3个回答
0
投票

[记住要加上“;”在这样的行的末尾

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);
}
}

1
投票

语句必须以;结尾

Statements (C# Programming Guide)

语句可以包含一行以结尾的代码 分号,或块中的一系列单行语句

Vector3 position = new Vector3(...); <== note the semicolon
Instantiate(...); <== note the semicolon

错误告诉您的是什么


0
投票

这就是您的脚本的外观。

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);
}
}
© www.soinside.com 2019 - 2024. All rights reserved.