Unity C# "Type 'Dropdown' does not contain a definition for 'value' "

Hey guys

I’m trying to reference the selected value of a dropbox but I’m getting the above error. I’m currently using

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;

Just trying a simple if statement like this below.

if(dropdown.value == 1)
{
Debug.Log(“Value: 1”);
}

Any help would be greatly appreciated.

What is dropdown?

Is it declared as Dropdown dropdown?

Yes, I’ve declared it as follows:

Dropdown dropdown = new Dropdown();

Is this your own Dropdown or the unity one? Normally you don’t declare stuff with New if it’s a unity object. This would include Dropdowns. (Also note if you have any addons that might include a Dropdown script of their own)

You’d either have to declare it as a public variable and drag and drop in the inspector or you can declare it and use a GetComponent() call on a gameobject that has your Dropdown or if the script is on the same object, you can just use GetComponent() without a target gameobject and it will get it off the same object the script is on.

As far as your error goes, I’m not getting an error from it myself. What version of unity are you using?