Posts

Showing posts from October, 2021

How to remove components through code in Unity? -- Unity

How to remove components through code in Unity? -- Unity   using Destroy [syntax] Destroy(<componentName>); where componentName is the component that will be destroyed. you can get a component by GetComponent method. more details on: Unity Remove Components Attached to GameObjects (monkeykidgc.com)

How to create a GameObject in Unity? -- Unity

 How to create a GameObject in Unity? -- Unity In general, you can create a GamObject with a few steps. Step1: Empty GameObject Step2: Add a Compoenent you nedd. How to create Empty GameObject: using new GameObject. e.g.  MyGO=new GameObject(); How to AddComponent: using AddCompoenent method of the GameObject. [syntax] (1)AddComponent<typename>(); (2)AddComponent(typeof(typename)); (3)AddComponent("<typename>"); //obsolete where typename is a name of component that your need. e.g. MyGO.AddComponent<Mesh>(); [NOTE] (1)AddComponent("<typename>"); //it is obsolete, I recommend that don't use it. more details on: Unity - Scripting API: GameObject.AddComponent (unity3d.com) But I don't find the way that creating 3D Object with AddComponent method. I find the new way. How to create 3D Object? using CreatePrimitive. [syntax] GameObject.CreatePrimitive (<typename>); where typename is a name of component that your need. e.g. plane = G...