[英]Type or namespace definition, or end-of-file expected (22,1) (UNITY)
Please fix my script, something is wrong!请修复我的脚本,有问题! I get this error, and I don't know what's wrong!我得到这个错误,我不知道出了什么问题! There's something wrong at the 22nd line.第 22 行有问题。
using System;
using System.Diagnostics;
using System.Web;
using UnityEngine;
public class Target : MonoBehaviour
{
// Start is called before the first frame update
public float health = 50f;
public void TakeDamage (float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}
Easiest things to check:最容易检查的事情:
It's possible that even though you wrote using UnityEngine;
即使您using UnityEngine;
, your code editor is bugging out and failing to recognize it. ,您的代码编辑器出现故障并且无法识别它。 VSCode has been particularly finicky for me lately in similar ways. VSCode 最近以类似的方式对我来说特别挑剔。 Here are some things you can try:以下是您可以尝试的一些事情:
Destroy(gameObject);
而不是Destroy(gameObject);
try putting UnityEngine.GameObject.Destroy(gameObject);
尝试把UnityEngine.GameObject.Destroy(gameObject);
This will force the compiler to use the right namespace for that function.这将强制编译器为该函数使用正确的命名空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.