From the course: Learning Unity 2D Scripting

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Talking to other scripts

Talking to other scripts - Unity Tutorial

From the course: Learning Unity 2D Scripting

Start my 1-month free trial

Talking to other scripts

- [Instructor] At this point, we now have two scripts attached to our gameObject. We have our first script, HelloWorld, and we have our second, which is the SpeedManager. What we're going to do is have one of our scripts read the value off of the other script. While it's important to keep this logic separated in order to favor composition over inheritance, we also want to make sure that some scripts are able to bridge the gap between each individual component and figure out how the system should work as a whole. To do this, let's switch over to MonoDevelop. If you remember, we copied the speed field out of HelloWorld and pasted it into the SpeedManager. The SpeedManager will store our speed value as we work on our game. We'll leave the logic inside of HelloWorld to actually move our gameObject. Let's go to the HelloWorld script. If we would have deleted the speed value earlier, it would have thrown an error and our game wouldn't compile. Let's create a new getter that will allow us to…

Contents