Unity 报错之 The same field name is serialized multiple times in the class or its parent class.

Unity 报错之 The same field name is serialized multiple times in the class or its parent class.

Unity 报错之 同一字段名在类或其父级中序列化多次


报错图片:

报错

报错代码:
public class BaseClass : MonoBehaviour {

    public GameObject gameStart;
}

public class SubClass : BaseClass
{
    //不管是否是同一类型都会报这个错误.
    public GameObject gameStart;
    //public Transform gameStart;
}

在写子类代码时,VS会提示我们父类中有此成员,有意隐藏请使用关键字new,如下图:

111


解决方案:直接使用父类的定义,若不满足需求则可在子类中重新起名即可.

PS:我遇到这个问题时,怎么修改都不好用,最后重启了下Unity就好了,就很奇怪啊…

发布了446 篇原创文章 · 获赞 630 · 访问量 50万+

猜你喜欢

转载自blog.csdn.net/Czhenya/article/details/104354728