Hello, Im getting the following error. Im trying to reference the text from the Scriptable scripts class and Im getting the following error .
error CS1061: Type `Scriptable.Info[]' does not contain a definition for `text' and no extension method `text' of type `Scriptable.Info[]' could be found. Are you missing an assembly reference?
The code
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Scriptable : ScriptableObject {
#region singleton
public static Scriptable instance;
public static Scriptable Instance
{
get{if(instance == null) instance = Resources.Load("Scriptable") as
Scriptable; return instance;}
}
#endregion
[System.Serializable]
public class Info{
public string text;
[Space()]
public float price = 0f;
public bool somethingElse = false;
public bool somethingMore = false;
public bool somethingEvenMore = false;
public bool thisIsSomething = false;
public bool somethingSomething = false;
}
public Info[] info;
}
and the script where I access it with is here
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class handler : MonoBehaviour {
public Scriptable script;
public Text thisText;
public string randomStringSelected;
void Start () {
Scriptable = transform.GetComponent<Scriptable> ();
if (script)
{
randomStringSelected = script.info.text.RandomItem(); //THIS IS WHERE THE ERROR SHOWS. Here .text is not shown in the auto completion.
thisText.text = randomStringSelected.toString();
}
}
}
public static class ArrayExtensions
{
public static T RandomItem<T>(this T[] array)
{
return array[Random.Range(0, array.Length)];
}
}
This is my 3rd post about this error. The user @Hellium keeps deleting it. I did try
using
script.info[index].text.RandomItem();
as suggested by him. But I get the error
Assets/Scripts/handler.cs(84,4): error CS0103: The name `index' does not exist in the current context