i have a question:
assume there is a script derived from monobehaviour, and i init it to different objects, such as A, B, but the props of them are not the same. and i test whether A == B, found that A always equals to B.
in my mind, different objects are not equal to another, but in unity, as long as it derived form monobehaviour, they are equals. what’s going on in the internal of monobehaviour?
I’m pretty sure that’s not the case. I’ve checked equality on MonoBehaviour references before and it behaves exactly as it should - returning true if the references are to the same object, otherwise false.
import UnityEngine
class MakeObjects (MonoBehaviour):
def Start():
person = gameObject.AddComponent(Person)
animal = gameObject.AddComponent(Animal)
if person == animal:
Debug.Log("${person.GetType()} and ${animal.GetType()} are the same.")
else:
Debug.Log("${person.GetType()} and ${animal.GetType()} are different.")
class Animal (MonoBehaviour):
Name as string
class Person (MonoBehaviour):
Name as string