Hello,
How do I access a scriptable object classes class from other script. Im trying to get the string and select randomly array from it and display it as a text.
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();
thisText.text = randomStringSelected.toString();
}
}
}