Least bad way to hold a static reference to Player


(Helios) #1

For the moment, I just want these things to go towards whatever thing I mark as the Player. Targeting will be more advanced in the future. I feel kind of gross even asking, but how would one go about making a kind of… global variable that holds a static reference to the Player?

Or, alternatively, is there a better way to do what I’m trying to do?

thing.goTowards(player)

is the idea.


(Jacob Albano) #2

You can do it like this:

// in Player constructor

name = "player";
// In your Enemy class:

override public function added():void
{
    this.playerRef = world.getInstance("player");
}