dropdown does not contain a defanition for 'value'

hi guys
im gettin the error
"dropdown does not contain a defanition for ‘value’ "
and am not shore why

here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Dropdown : MonoBehaviour {
public Dropdown drop;

void Update () {
if (drop.value == 0){
//do something
}
}

unity 5.5.2f1

Use code tags when posting code.

You don’t have any variable called “value” in your class. What are you expecting it to find there?

I have a feeling that you’re doing something weird, because your code is basically using a different object of type Dropdown (even though it’s running on an object of that type in the first place).

You named your own class Dropdown, so when you include a member field of type Dropdown, the C# compiler has to do name resolution and decides that it’s referring your very own class, rather than UnityEngine.UI.Dropdown (which is what I’m guessing you want it to be). That’s just a consequence of how C# does name resolution, how it prioritizes when there are multiple possible names that match.

Either rename your own class to something other than simply Dropdown, or qualify your member field drop to explicitly be of type UnityEngine.UI.Dropdown.

1 Like