Unityengine.ui vs code

Hello, I’ve searched for an answer, but everyone seems to be using vs 2019. I’m using VS Code, which I was recommended by the “Unity Game Development Build 2d, 3d Games” course since vs 2019 is very heavy and takes a lot of time to run. Currently I’m taking the “Complete C# Unity Game Developer Course” and I’ve gotten to the moment where I need to add ’ using UnityEngine.UI; ’ and ’ Text textComponents; ’ to my code. However, it says that the namespace UnityEngine.UI doesn’t exist. I was hoping for a solution that was compatible with VS Code instead of 2019, hopefully in terms I an understand since I am only beginning.

Hi Amber,

Welcome to our community! :slight_smile:

Please follow the instruction on this website. Maybe Is Visual Studio Code was not selected as your External Script Editor in Unity (Edit > Preferences > External Tools). Or the Unity Tools extension is missing. Or something else is the case.

VSC should definitely be compatible with Unity 2019. Or are you using an older version of Unity? If so, which one?

Hello, I just restarted, and went through the instructions and seem to have done these steps already. I’m currently using 2019.3.4f1 . I’ve looked online for my problem, and it seems to be a common bug that has gone back years. But everyone seems to have different solutions, that aren’t reproducable, in a sense that it was their own issue and not another’s. Also, I don’t entirely understand the coding language, or file names, etc, when reading the solutions either.

Could you share a screenshot of your code in Visual Studio code? (As an exception! I usually prefer formatted text.)

Maybe I will be able to spot an issue.

Is the latest .NET Framework installed on your computer?

using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class AdventureGame : MonoBehaviour

{

[SerializeField] Text textComponent;

[SerializeField] State startingState;

// Start is called before the first frame update

State currentState;

void Start()

{

    currentState = startingState;

    textComponent.text = currentState.GetStoryState();

}

// Update is called once per frame

void Update()

{

    ManageState();

    

}

private void ManageState()

{

    var nextStates = currentState.GetNextStates();

    if(Input.GetKeyDown(KeyCode.Alpha1))

    {

        currentState = nextStates[0];

    }

    else if(Input.GetKeyDown(KeyCode.Alpha2))

    {

        currentState = nextStates[1];

    }

    textComponent.text = currentState.GetStoryState();

}

}

so the ui and text are both seen as incorrect. I should mention now that i moved on, with the intent of learning even if it didn’t work, and the code actually works still in unity, vs just doesn’t acknowledge that it’s fine.

So if it’s nothing to worry about, I’ll just push on, but I don’t know if there will end up being problems come build time or something having “errors” in my code.

Red errors should always be fixed before you build your game. Unfortunately, I cannot spot any issue in your code.

I’m wondering if the issue is caused by a bug. I vaguely remember that UnityEngine.UI was not recognised by one of the Unity 2019 versions. Maybe that’s the case here? If possible, try to update to the latest stable version of either 2019 or 2020.

Okay, I’m glad it’s narrowed down at least to a bug, and hopefully that works or it’s fixed with an update, thank you.

Well, it was just a guess. I could be wrong. Please let me know if updating worked. :slight_smile:

How are you getting on with this, @Amber_Rose?


See also:

Technically I still haven’t found a solution for this, but since it isn’t calling an error in Unity itself, I don’t mind marking it as solved.

Privacy & Terms