原文地址:https://support.unity3d.com/hc/en-us/articles/207443183-What-is-CS0127-
症狀
當嘗試進入Play模式時,我得到了如下錯誤:
error CS0127: `__’: A return keyword must not be followed by any expression when method returns void
原因
引起CS0127號錯誤的原因是,某個返回值類型爲void的方法嘗試返回一個值。
本例子的錯誤信息如下:
error CS0127: `ExampleScript.MyMethod()’: A return keyword must not be followed by any expression when method returns void
解決方案
改變方法的返回類型爲它將會返回的類型,可以解決CS0127錯誤。本例中,方法的返回類型爲int,因爲我們將要返回一個值爲7的int類型。
更多信息
https://msdn.microsoft.com/en-us/library/wttka33z(v=vs.90).aspx