Posts

Showing posts from October, 2021

How to quit application through script in Unity? -- Unity

 How to quit application through script in Unity? -- Unity Stop running  game at runtime. Debug.Break(); Close the Unity Application. EditorApplication.Exit(0);  Quit the deployed game/App. Application.Quit(); source: unity3d - How can i stop unity from script? - Stack Overflow

How to color a cube object with different color in different side? Unity -- coloring Object

 How to color a cube object with different color in different side? Unity -- coloring Object more details. See Help Wanted - Shader Graph Apply Different colours onto different sides of the model - Unity Forum

How to fetch the object which the object collides with? Unity -- collision

 How to fetch the object which the object collides with? Unity -- collision [Ans] collision.gameObject.name; public void OnCollisionEnter(Collision collision)     {                    Debug.Log("collision name:" + collision.gameObject.name);              } Step1: make a collision event with the step in the following link How to do somethings after collision between two objects? -- Unity -- Collision (programmingunitycsharp.blogspot.com) (my article) Step2: In Script, write the line Debug.Log("collision name:" + collision.gameObject.name); 

How to do somethings after collision between two objects? -- Unity -- Collision

Image
 How to do somethings after collision between two objects? -- Unity -- Collision [Ans] OnCollisionEnter or OnTriggerEnter func. Suppose that when ACube object collides with Ground_Cube object, it will trigger event. Do following steps. Step1:  In Unity, add collider as component in ACube. Step2: In Unity, add collider as component in Ground_Cube. Step3: In Unity, add Rigidbody as component in ACube. Step4: Great Importance!!! Check the setting in Rigidbody in Ground_Cube,  collider in ACube and collider in Ground_Cube. Step5: In Script, override the OnCollisionEnter func. public void OnCollisionEnter(Collision collision) { //Do something } [NOTE] Great Importance!!! (1)Unity is a case-insensitive language. i.e. In Unity, uppercase and lowercase letter are different. onCollisionEnter is not accepted. If you spell it wrong, the func. will be recongized as your own func. If you do so, compiler will not throw error, but it can not work. (2)OnCollisionEnter func. must take 1 p...

How to fetch value from other script through code in Unity? -- Unity -- fetch script

How to fetch value from other script  through code in Unity? -- Unity -- fetch script [Ans] target script->destination script If I wanna fetch a value and store it into destination Script from target destination. I have to drag GameObject which is attached to target script to destination script. Step1: write a target script. Step2: write a destionation script. Step3: drag the component which attach the target script into the destination script. e.g. If I wanna change TextListScript.num to 20 in other Script, I will do following. In destination Script ButtonEventScript: public class ButtonEventScript { public TextListScript MyScript; MyScript.num=20; } In target Script  TextListScript: public class TextListScript { public int  num=0; } And Assuming that obj is attached to TextScript. I have to drag TextScript into MyScript field. That's done.