My code matches exactly what is shown in the lecture, but I don’t see the Text component being added in the Inspector.:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AdventureGame : MonoBehaviour
{
[SerializeField] Text textComponent;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
In talking to a friend that knows Unity we still couldn’t figure out why this was failing. He wrote the same code using 2019.3.6f1 and it worked fine. He sent that to me and it looked fine when I loaded it into my 2019.3.9f1 version.
So at his suggestion I closed out my Unity session and re-opened it. Now the component showed correctly.
So the question still remains: Why is it not working like in the demo?
It will be a big hindrance if I have to close it and re=open every time I add a component in the C# script like this.
Is your script saved correctly? Have you tried to restart Unity? Have you tried to remove and to reassign the script?
There seems to be a message in your console which claims there were compiler error. Since your script looks fine, I suspect there could be an issue with Visual Studio. Please watch lecture “Fixing Visual Studio Problems” (currently #4).
Now that you mention it I see the message at the bottom of the screen. I had missed that. Not sure why it is there, because when I exited Unity and brought the project back up in Unity it was fine. The changes had certainly been saved and my code matched exactly what was being shown in the video.
I have noticed that I am not getting completion of the text as I type it for most things, so I intend to look at the settings to see if that is somehow turned off. That might also be preventing it from flagging errors when I look at it in VS2019.