A very short and concrete question!
Debug.Log(this.gameObject.name == "Enemy_HoverBot1");
Both these two Debug.Log() sentences return always false even though one of the gameObjects having the script attached both is named “Enemy_HoverBot1” and has the tag “Enemy” and similar for most of the other gameObjects, Why? And can someone please tell me what should be written to get true in this particular situation (which means the game works correctly and not only writing out true in the Debug.Log() sentence. Thanks.
That’s actually very unlikely. Why haven’t you just printed out the name and the tag in your debug log? You generally should avoid just printing out single values. If you do this alot you have no idea where the log comes from.
Try something like this:
Debug.Log("gameObject.name = " + gameObject.name, gameObject);
Debug.Log("is gameObject.name equal to Enemy_HoverBot1: " +
Debug.Log("gameObject.tag = " + gameObject.tag, gameObject);
Debug.Log("gameObject.CompareTag(\"Enemy\")) = " +
This will produce much clearer log messages. Also note that I added “gameObject” as second parameter to Debug.Log. The second context parameter can be any UnityEngine.Object reference. The point of this is when you click on the log message in the console, the Unity editor will highlight / ping that object either in the hierarchy or the project view. Maybe you execute this code not on the object you think you do. If this is the case we need much more context of your code. Looking at the stacktrace of those log messages might help to identify the issue.
I guess this is related to your other question over here? Since we have no idea where this code is actually executed we can only speculate what is happening. Do you have those logs in Awake or Start of the script? If it’s in a custom method, nobody knows on which object you actually call it and from where.