Posts

Showing posts from August, 2021

output message to Unity Console - Debug.Log() v.s. Debug.LogWarning() v.s. Debug.LogError() v.s. print()

Image
 output message to Unity Console - Debug.Log() v.s. Debug.LogWarning() v.s. Debug.LogError() v.s. print() usage and description: 1.Debug.Log(string message) The message will be printed in Unity Console. You can see it in Unity Console with General mode. 2.Debug.LogWarning(string message) The message was considered as a warning. Then the message will be printed in Unity Console. You can see it in Unity Console with Warning mode. When you see it you will see a warning figure(similar to a yellow triangle). 3.Debug.LogError(string message) The message was considered as a Error. Then the message will be printed in Unity Console. You can see it in Unity Console with Error mode. When you see it you will see a Error figure(similar to a red octagon). 4.print(string message) have same result with using  Debug.Log(string message). my blogger can explain that little difference  between Debug.Log() and print() Debug.Log() v.s. print() (programmingunitycsharp.blogspot.com) screenshot: ...

Debug.Log() v.s. print()

Image
 Debug.Log() v.s. print()  difference bewtween Debug.Log() and print(): In fact, they are identical. print() is a simple encapsulation of Debug.Log() According to the following screenshot. We can know Debug.Log() is in the class UnityEngine. And print() is in the class UnityEngine.Monobehaviour. screenshot:     code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PrintScript : MonoBehaviour {     [Header("Counter")]     public int Counter = 0;     [Header("Message")]     public string Message = "not initialized!";     // Start is called before the first frame update     void Start()     {              }     // Update is called once per frame     void FixedUpdate()     {         ChangeMessage();     }     private void ChangeMessage()     { ...

usage of Renderer.enabled

 usage of Renderer.enabled usage: An attribute which makes the rendered 3D object is visible or not. If it is set to false, the object will be set to be invisible. You can hide the gameObject with the following code: Render rend=this. gameObject.GetCompoent<Renderer>();  rend.enabled=false; word definition Renderer: definition: A renderer is what  makes an object appear on the screen . (from Unity documentation) Render: definition to cause  someone or something to be in a particular state. (from Oxford Cambridge) -er: suffix -er mean a person who does it. source: more details on   Unity - Scripting API: Renderer.enabled (unity3d.com)

GameObject.SetActive() v.s. GameObject.active

 GameObject.SetActive() v.s. GameObject.active usage: attribute active of a GameObject checks whether  the GameObject is active or not. method SetActive(bool b) of GameObject  is a method that sets the attribute of GameObject active is b. When you use GameObject.SetActive (false) or GameObject.active=false to deactivate the GameObject, then OnDisable() event will be triggered. After that, the GameObject.active will set to be false and  GameObject will be deactive. When you use GameObject.SetActive(true) or GameObject.active=true to activate the GameObject, then OnEnable() event will be triggered. After that, the GameObject.active will set to be true and  GameObject will be active. I prove it on my script. Unity Version: 2020.3.12f1.590.2 Personal NOTE:  When the GameObject is deactive, you can  NOT  acess it and its compoent including its  BoxCollider , Script which is attcahed to GameObject and transform etc. When the GameObject is deactiv...

Unity-Why can not change the view of main Camera into a position of the GameObject?

Unity-Why can not change the view  of main Camera into a position of the GameObject? A:For change the position  of main camera. You should (1)select the main camera with Camera class using the following code: Camera cam=Camera.main; (2)change the position.  Notice that when you change the localPosition (position which is relative to the parent GameObject) You should add it to fix the position. Here is my code: cam = Camera.main; offset=Unitychan_GameObject.transform.localPosition+UnitychanFace_GameObject.transform.localPosition+this.transform.localPosition;  cam.transform.localPosition = UnitychanEyes_GameObject.transform.localPosition + offset; P.S. localPosition  is a Position which is relative to parent GameObject.

Reseason about the fact that OnCollisionEnter event was not triggered when a GameObject touched the other GameObject.

Reseason about  the fact that  OnCollisionEnter event was not triggered when a GameObject touched the other GameObject. Q:I stuck on a problem. I  try to develop a new project with Unity. Sometimes,  a gameObject  named unitychan did not pass throught the wall which is left to it the first time it touched the wall. But unitychan passed through the wall which is left to it the second time it touched the wall then I saw uniychan dropping. Sometimes, uniychan passed through the wall which is back to it the first time it touched the wall. I take a look at the the setting of the GameObject in inspector and I ensured that two components(BoxCollider) of two GameObject were attatched. I stuck it on the similar problem with the third time I looked at it for 4 days. I finally solved it on third time (at 2021/08/05 p.m. 3:xx). What happened? P.S. PlayerControl.cs script was attached on unitychan GameObject. The wall was tagged with "Wall_Tag". The thickness of the wall is ...