原文地址:https://support.unity3d.com/hc/en-us/articles/206829863-What-is-CS0236-
症状
当尝试进入Play模式时,我得到了如下错误:
error CS0236: A field initializer cannot reference the nonstatic field, method, or property `__’
原因
当一个非局部变量引用一个非静态的变量时会发生CS0236错误。见下面的例子:
实例变量不应这样子赋值。
本例子的错误信息如下:
error CS0236: A field initializer cannot reference the nonstatic field, method, or property `ExampleScript.playerObj’
解决方案
可以在一个方法里给实例变量赋值,比如Start或者Awake方法。见下图:
更多信息
https://msdn.microsoft.com/en-us/library/5724t6za(v=vs.90).aspx