Search code examples
c#unity-game-enginegameobject

Why is my variable not accessible?


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));
    }

}

In the code im trying to access "selected_model" from 3 different places. But non of them works. The debugger gives the following error.

Assets/Scripts/objectControl.cs(15,17): error CS0103: The name `selected_item' does not exist in the current context


Solution

  • You defined it as public char slected_item = 'F';

    missing an e in selected ;)

    It's not complaining about selected_model, it's just that you have misspelled selected. Surely this should be easily visible in the IDE?