I want to create a relatively simple UI via C# script only and it should have a simple background rectangle.
For that I created a canvas via C# and want to place some other elements in it.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Test : MonoBehaviour
{
private void Awake()
{
GameObject obj = new GameObject();
Canvas canvas = obj.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.pixelPerfect = true;
}
}
There isn’t any class named Panel but instead UnityEngine.UI.Image is used however it cannot be instantiated (protected constructor, WTH?)
What’s the best way to create a simple, colored bg rect via script for the Unity UI system?