Adventures in GameDev with GameDevHQ! Day 15: Script Communication in Unity with GetComponent.

Player player = other.transform.GetComponent<Player>();

other.transform

remember that in unity, we can only access another objects transform directly. If we want anything else, we’ll need GetComponent:

other.transform.GetComponent<Player>();
Player.Damage();

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store