#Cant pass gameobjects or transforms with unity event

4 messages · Page 1 of 1 (latest)

vagrant bay
#

How can we pass a object with unity event. I'm getting this error. But passing string is okey.

"ArgumentException: Object of type 'UnityEngine.Object' cannot be converted to type 'UnityEngine.GameObject'."

zinc nova
#

It seems (to my surprise) that "this" and "this.gameObject" are not the same. The former one refers to the instance of the object, while the latter refers to the game object.
The difference is not clear to me, but it seems like you should use "this.gameObject"

#

Ah, got it... "this" is the instance od the script itself

#
  • this: Refers to the current instance of the class (the script itself)
  • this.gameObject: Refers to the GameObject to which the current script is attached.