Clarification on giving the start and end waypoints Type Waypoint

I am starting to get confused on the Types and classes and such.

1a.) What is the benefit of giving startWaypoint and endWaypoint the Type Waypoint?
1b.) Could I have given them a different type? Or are we going to do something special later on with this information (I am betting we will.) I originally was going to give them type GameObject with serializedFields in the inspector, drag and drop the two Tops into them. Tthen specifically modify the mesh renderers of the two Tops we are using for the start and end like we did in SetTopColor. Would that have worked as well? At least for just coloring them?

2.) Once I create a script named Waypoint, it creates a Class named Waypoint that I can access/use in all scripts? Is this regardless of where in the game this script is attached? (Meaning I should not and cannot reuse the ‘Waypoint’ with the capital ‘W’ anywhere else in my game without causing problems?)

Thanks in advance for all the help!

Sincerely,

Ryan

1 Like

Hey Ryan!

On giving startWaypoint and endWaypoint the type Waypoint, you do that because the pathfinder is built around the class Waypoint. When you make a script called Waypoint, you’re both making a script file that you can edit and also declaring a new class, Waypoint, for all of the scripts in that game (and just in that game).

Bear in mind, that things like float, int, Vector3, are all classes. They’re just something like the scripting equivalent of primatives and come pre-built and ready to use. When you make that Waypoint script, you’re adding a new class that you can use to declare variables. For something like startWaypoint, you’re declaring a new empty thing of type Waypoint (vs float, integer, etc).

The reason you do all that in this case, is Waypoints are ALSO on things in your game. In this case, blocks that makeup the grid. Each one is a different Waypoint, so if you can find that Waypoint, you also get useful info about it. Where it is, what color the top is, etc.

And yeah, once you’ve declared a class, you can’t use the same word without referencing the class. Capitalization matters, so you can still call something “waypoint”, but not “Waypoint”

Hope that helps!

Lee

1 Like

Thank you! That was exactly the explanation I was looking for!!!

Thanks again!

Sincerely,

Ryan

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

Privacy & Terms