Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 类、结构或接口成员声明中的无效标记“')和“{”_C# - Fatal编程技术网

C# 类、结构或接口成员声明中的无效标记“')和“{”

C# 类、结构或接口成员声明中的无效标记“')和“{”,c#,C#,该错误发生在所有出现的“{”和 我看不出有什么不对劲吗 // Kills the game object Destroy{}(gameObject); // Removes this script instance from the game object //Destroy(this); // Removes the rigidbody from the game object Destroy{}(rigidbody); // Kills the game object in 5 sec

该错误发生在所有出现的“{”和 我看不出有什么不对劲吗

// Kills the game object
Destroy{}(gameObject);

// Removes this script instance from the game object
//Destroy(this);

// Removes the rigidbody from the game object
Destroy{}(rigidbody);

// Kills the game object in 5 seconds after loading the object
Destroy{}(5, gameObject);

// When the user presses Ctrl, it will remove the script 
// named FooScript from the game object
void Update()
{
    if (Input.GetButton("Fire1")) 
        GetComponent<FooScript>();
    {
        Destroy(GetComponent<MonoScript>());
    }
}
所有这些销毁方法都应该是某种方法的一部分。 他们不可能在那样的课堂上晃来晃去。 此外,{}在打开新作用域时使用,而不是在调用方法时使用。代码可能如下所示:

// What are these? They should be in some method
void DestroyAll()
{
    // Kills the game object
    Destroy(gameObject);

    // Removes this script instance from the game object
    //Destroy(this);

    // Removes the rigidbody from the game object
    Destroy(rigidbody);

    // Kills the game object in 5 seconds after loading the object
    Destroy(5, gameObject);
}

// When the user presses Ctrl, it will remove the script 
// named FooScript from the game object
void Update()
{
    if (Input.GetButton("Fire1"))
    {
        Destroy(GetComponent<FooScript>());
    }
}

为什么你认为你需要{}?只要在所有情况下删除{},它就会工作。销毁{}gameObject;应该是销毁gameObject;…除了在无效更新中。:-@LarsTech是的,我想我不清楚-我是指所有具体的{}情况,而不是一般的花括号:如果我删除它们,我会在Destroy上得到一个错误,声明“Destroy.DestroygameObject”必须声明一个body,因为它没有标记为abstract、extern或partialIn,如果您不知道的话,但是DestroyGetComponent;不是If子句的一部分。您的括号使它看起来可能令人困惑。