Hello, I posted a whie back about an issue I was having with presets and their parent objects. I decided to try a new approach that would not use any presets in hopes of avoiding these kinds of errors. I am now having an issue with the Resources folder that I have in that when the script I have attempts to retrieve a text resource from the folder, it cannot seem to find it. I looked up solutions, and it appears to me that I did exactly what the Unity manual explains, but it does not seem to be working for me (Here is the manual if you want to see it: Unity - Manual: Loading Resources at Runtime ). Am I missing something? Here is the code and error messages in case it is relevant.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class QuizManager : MonoBehaviour
{
public GameObject canvas;
GameObject CreateText(Transform canvas_transform, float x, float y, string text_to_print, int font_size, Color text_color)
{
Font arial;
GameObject UItextGO = new GameObject("question");
UItextGO.transform.SetParent(canvas_transform);
RectTransform trans = UItextGO.AddComponent<RectTransform>();
trans.anchoredPosition = new Vector2(x, y);
arial = (Font)Resources.GetBuiltinResource(typeof(Font), "Roboto-Bold.ttf");
Text text = UItextGO.AddComponent<Text>();
text.font = arial;
text.text = text_to_print;
text.fontSize = font_size;
text.color = text_color;
return UItextGO;
}
public void Start()
{
GameObject UItext = CreateText(canvas.transform, 100, 100, "Question 1", 24, Color.black);
}