期望的类在c#为统一

本文关键字:期望 | 更新日期: 2023-09-27 18:06:31

我在使用这个脚本时遇到了很多问题(我是c#新手)

using UnityEngine; 
public class Death : MonoBehaviour{}
public void Add() //right here I get a "expected class, Delegate, Enum, interface, or struct" error. 
if (isDead) 
{
    DeathCamTag.SetActive(true); 
}
else 
{
    FPSControllerTag.SetActive(true);   
} 

如果我把它改成:

using UnityEngine;
public class Death : MonoBehaviour{}{ //namespace dose not directly contain members such as methods
public void Add() //expected class
if (isDead) 
{
    DeathCamTag.SetActive(true); 
}
else 
{
    FPSControllerTag.SetActive(true);   
} 
} //type or namespace def or end of file expected

谢谢

期望的类在c#为统一

应该是这样的

using UnityEngine;
namespace ClassLibrary1
{
    public class Death : MonoBehaviour
    {
        public void Add() //right here I get a "expected class, Delegate, Enum, interface, or struct" error. 
        {
            if (isDead)
            {
                DeathCamTag.SetActive(true);
            }
            else
            {
                FPSControllerTag.SetActive(true);
            }
        }
    }
}

您需要一个名称空间,而您缺少一堆{}。试一试:

using UnityEngine;
namespace GOTY2015 
{    
    public class Death : MonoBehaviour
    { 
        public void Add() 
        { 
            if (isDead) 
            {
                DeathCamTag.SetActive(true); 
            }
            else 
            {
                FPSControllerTag.SetActive(true);   
            } 
        }
    }   
}