【问题标题】:Why is my variable not accessible?为什么我的变量无法访问?
【发布时间】:2011-10-04 08:04:16
【问题描述】:
using UnityEngine;
using System.Collections;

public class objectControl : MonoBehaviour {

    public char slected_item = 'F';
    public int selected_model = 0;
    public GameObject f,o,d;

    // Use this for initialization
    void Start () {
        f = GameObject.Find("f");
        o = GameObject.Find("o");
        d = GameObject.Find("d");
        selected_item = 'F';
    }

    // Update is called once per frame
    void Update () {
        selected_item = 'F';
        if (Input.GetKey(KeyCode.F)){
            selected_item = 'F';
            doSelectedAnimation();
        }
    }

    void doSelectedAnimation(){
        iTween.MoveTo(f,iTween.Hash("y",-3,"time",4));
    }

}

在代码中,我试图从 3 个不同的地方访问“selected_model”。但它们都不起作用。调试器给出以下错误。

Assets/Scripts/objectControl.cs(15,17):错误 CS0103:当前上下文中不存在名称 `selected_item'

【问题讨论】:

    标签: c# unity3d gameobject


    【解决方案1】:

    您将其定义为public char slected_item = 'F';

    selected 中缺少e ;)

    不是在抱怨selected_model,只是你拼错了selected。这在 IDE 中应该很容易看到吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-02
      • 2020-06-20
      • 2022-01-08
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      相关资源
      最近更新 更多