Unity Create UI control from script

You are supposed to make the Toggle the child of the Canvas. You didn’t do that in your code. Also, you move a UI component and GameObject with newGO.GetComponent<RectTransform>().anchoredPosition3D not newGO.transform.position. There are 3 Ways to create a Complete UI Control in Unity: 1.Use the DefaultControls API to generate it (Easy and Recommended) With the … Read more

Enable/Disable VR from code

Include using UnityEngine.XR; at the top. Call XRSettings.LoadDeviceByName(“”) with empty string followed by XRSettings.enabled = false; to disable VR in the start function to disable VR. When you want to enable it later on, call XRSettings.LoadDeviceByName(“daydream”) with the VR name followed by XRSettings.enabled = true;. You should wait for a frame between each function call. … Read more

Move GameObject over time

gjttt1’s answer is close but is missing important functions and the use of WaitForSeconds() for moving GameObject is unacceptable. You should use combination of Lerp, Coroutine and Time.deltaTime. You must understand these stuff to be able to do animation from Script in Unity. public GameObject objectectA; public GameObject objectectB; void Start() { StartCoroutine(moveToX(objectectA.transform, objectectB.transform.position, 1.0f)); … Read more

Using new Unity VideoPlayer and VideoClip API to play video

Found the problem. Below is the FIXED code that plays Video and Audio: //Raw Image to Show Video Images [Assign from the Editor] public RawImage image; //Video To Play [Assign from the Editor] public VideoClip videoToPlay; private VideoPlayer videoPlayer; private VideoSource videoSource; //Audio private AudioSource audioSource; // Use this for initialization void Start() { Application.runInBackground … Read more

How to find the size of Object and show it on screen [closed]

You can get your object size like this: public double GetObjectSize(Object Obj) { using (var m = new System.IO.MemoryStream()) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); b.Serialize(m, Obj); double size = Convert.ToDouble(m.Length); return size; } } But consider that not all objects are serializable. And it will not serialize nested objects too deep.