How to add custom class as a component to gameobject in unity?

So I have a prefab which is Instantiated in run time, to that prefab I create and add another game object with components Image as a child. Now here how can I add a custom class data as component to the newly created child of prefab? >Solution : To be able to add your custom… Read More How to add custom class as a component to gameobject in unity?

How can I Initialize an array in class?

public class DataClass { public int[] collectionData; } [SerializeField] private DataClass[] DataClassArray; I have created above field in which class consists of an array, and the object of that class is also an array. public void GenerateCategariesData() { Debug.Log("==========>******" + bookCatogaryObject.Data.Rows.Count); collectionCounts = new int[bookCatogaryObject.Data.Rows.Count]; DataClassArray = new DataClass[bookCatogaryObject.Data.Rows.Count]; for (int i = 0; i… Read More How can I Initialize an array in class?

If I assign an Object as GameObject, I cant get the RectTransform to work. How to fix that?

I want to give my Parent GameObject Inventory spicific rec-coordinates via this line of code: Inventory.GetComponent<RectTransform>().position = new Vector3(500f, 0f, 0f); In the editor, the object Inventory is assigned as a GameObject, so it keeps changing the rec-coordinates to world-coordinates. I’ve tried assigning the Inventory as a Transform and RectTransform but it says that there… Read More If I assign an Object as GameObject, I cant get the RectTransform to work. How to fix that?

How can i get an ui element to point towards a position that is in world coordinates in unity?

So im trying to make an arrow point towards a position in my scene, i want to rotate the arrow to that position. I have tried to make the world position into a screen position and then subtracting the position of the arrow from that and then settig the rotation, but im having some trouble… Read More How can i get an ui element to point towards a position that is in world coordinates in unity?