Communicating between Scripts like with Cursor and Camera Raycaster

Hey all,

I was wondering.
The video has us placing the Camera Raycaster and Cursor scripts on the same gameObject, the Camera Arm.
I made the mistake of placing the Cursor script on the Main Camera, and the Camera Raycaster script on the Camera arm.

Of course, this didn’t work. But, Why?

What is this communication called? I know we went over this before in this, or the last course. Is this like “SendMessage” where the scripts can only communicate upwards in the hierarchy or something?

Thank you in advance!!

–Nibernator

Hi,

In your example, when the scripts were on the same GameObject they were components of that GameObject. A reference can be created between them by using GetComponent, it’s this reference that is important.

When your script components were on different GameObjects, assuming you were still using GetComponent in one of the scripts it would have returned null, e.g. it couldn’t find the component and as such has no reference to it.

You may be thinking of delegates, where you subscribe to an event and then these delegates are notified when that event occurs.

Hope this helps. :slight_smile:

Ohhhhhhhhhh! Okay, this makes sense!

Thank you for the quick reply! I truly appreciate it!

-Ryan

1 Like

You’re very welcome Ryan.

Couple of links below which may also be of use. :slight_smile:


See also;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms