Working . . . but code is showing me squiggly lines

Hey everyone, my code is working, but in the second code the State is getting a red line under it saying the namespace can not be found.

Also in the first set of code my ScriptableObject does not turn blue like my Monobehaviour in the second.

As I said it works, and I could continue on, but am curious as to way this is. Much thanks

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

//this creates a new option if you rick click to add an asset

[CreateAssetMenu(menuName = “State”)]

public class State : ScriptableObject
{
//TextArea allows use to put a text area in our inspector to write in
[TextArea(10,14)][SerializeField] string storyText;
//first number is minimum size of our field where we write in our text
//second number is amount of lines before we see the side scroll bar

public string GetStateStory()
{
    return storyText;
}

}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//we type in this namespace leting the program know we are using the Unity.Engine.UI
//and all the info in there, we want access to. So now we can use our Text below
public class AdventureGame : MonoBehaviour
{

//putting SerializeField in front of any var. it is now
//avalible in inspector to be used. Remember to drag your componenet 
//to link it up
[SerializeField]  Text textComponent;
[SerializeField]  State StartingState;

State state;

// Start is called before the first frame update
void Start()
{
    state = StartingState;

    //this is telling the script to access text componenet, and within
    //text.component I want you to use the text property
    textComponent.text = state.GetStateStory();
}

// Update is called once per frame
void Update()
{
    
}

}

1 Like

I wasn’t able to reproduce your error.

It probably has something to do with the code editor of your choice or Unity, you might be able to fix it, but be aware, according to other people in Unity’s forums, the solution might break your entire game - Close Unity, delete the Library Folder inside your project’s main folder.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms