Hey
I am having a problem where I am creating a new GameObject and can’t seem to change the sizeDelta of it’s RectTransform. I just get the error "
Assets\Scripts\Ship Builders\BoatShopList.cs(31,19): error CS1061: ‘GameObject’ does not contain a definition for ‘RectTransform’ and no accessible extension method ‘RectTransform’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)"
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class BoatShopList : MonoBehaviour
{
public int Height;
public int tb;
public TextAsset file;
public int i = 0;
public string PanelName;
GameObject gameObjectShipBuilders;
// Start is called before the first frame update
void Start()
{
Load(file);
tb = int.Parse(Find_number_entries("TRUE").name);
Height = tb * 105;
RectTransform rt = GetComponent<RectTransform>();
rt.sizeDelta = new Vector2(4, Height);
gameObjectShipBuilders = GameObject.Find("Content");
while (i < tb)
{
PanelName = "Panel" + i;
GameObject panel = new GameObject(PanelName);
panel.AddComponent<CanvasRenderer>();
panel.AddComponent<Image>();
panel.transform.parent = gameObjectShipBuilders.transform;
panel.RectTransform.sizeDelta = new Vector2(4, 95);
i++;
}
}
Thanks in advance!