You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity 2017 UnityScript子类变量歧义:如何指定本地preview变量

Fixing Ambiguous Reference to preview in UnityScript Editor Class

The ambiguity error you're seeing comes from the fact that both your CameraMotionBlurEditor subclass and the parent Editor class have a variable named preview. To explicitly target your subclass's local variable instead of the inherited one, you can use the this keyword to qualify the reference.

Corrected Code Example

Update your OnInspectorGUI method to use this.preview to specify the local subclass variable:

function OnInspectorGUI () { 
    if (this.preview.boolValue) {
        dosomething();
    } 
}

Why This Works

In UnityScript (Unity's JavaScript-based scripting language), the this keyword refers directly to the current instance of your subclass. By prefixing preview with this., you're telling the compiler to prioritize the SerializedProperty you declared in CameraMotionBlurEditor over any identically named variables inherited from the parent Editor class. This eliminates the ambiguity and ensures you're accessing the correct variable.

内容的提问来源于stack exchange,提问作者Randy Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:05:47