[英]Invalid token ';' in class, struct, or interface member declaration
[英]Invalid token ')' and '{' in class, struct, or interface member declaration
错误发生在所有出现的 '{' 和 ')' 我没有看到任何错误?
// 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>());
}
}
所有这些Destroy
方法都应该是某个方法的一部分。
他们不能在这样的班级里晃来晃去。
此外, {}
在打开新范围时使用,而不是在调用方法时使用。 代码可能看起来像:
// 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>());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.