I want the see the properties of the class Room from another script in the Inspector of an instantiated Button.
It only works when I set class Room to MonoBehaviour, but than I get some warning when I try to create objects out of Room in the class CreateRoom.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Room {
public int RoomNR;
}
Create Rooms looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CreateRoom : MonoBehaviour {
public Room room;
public GameObject RoomButtonPrefab;
void Start()
{
GameObject RoomButtonPrefabClone = Instantiate(RoomButtonPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
RoomButtonPrefabClone.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
RoomButtonPrefabClone.AddComponent<Room>();
}
}
When I try this it says:
The type ‘Room’ cannot be used as type parameter ‘T’ in the generic type or method ‘GameObject.AddComponent()’…
What can I do to solve this?