Skip to main content
fixed link title
Source Link
Daniel
  • 3.5k
  • 8
  • 37
  • 55

Unity3Unity3DD uses a component-based system by default. It is superb for creating game entities from a text file and dependency injection.

function createEnemy() {
   
   // extract AI type for enemy
   // definition is a custom structure holding parameters to create the enemy
   var aitypename = definition.ai;

   // AIType can be an interface or abstract class
   // you can create a component from a string or from a type
   var ai : AIType = this.gameObject.AddComponent(aitypename);
   ai.setup(definition.ai_settings);

   // set rule for enemy when it is destroyed
   this.gameObject.AddComponent(definition.when_destoryed); 
 

}

Those components could look like this

class AI_Scout extends AIType
{
  // called per update-frame on the game-object with this script
  public function Update() {
    // run Scout AI here
   }
}


class Spawn_Ammo_On_Destroyed extends When_Destroyed
{
   // automatically called by the engine when the game object this script is attached to is
   // destroyed
   public function OnDestroyed() {
    // spawn ammo
    }
}

Unity3D uses a component-based system by default. It is superb for creating game entities from a text file and dependency injection.

function createEnemy() {
   
   // extract AI type for enemy
   // definition is a custom structure holding parameters to create the enemy
   var aitypename = definition.ai;

   // AIType can be an interface or abstract class
   // you can create a component from a string or from a type
   var ai : AIType = this.gameObject.AddComponent(aitypename);
   ai.setup(definition.ai_settings);

   // set rule for enemy when it is destroyed
   this.gameObject.AddComponent(definition.when_destoryed); 
 

}

Those components could look like this

class AI_Scout extends AIType
{
  // called per update-frame on the game-object with this script
  public function Update() {
    // run Scout AI here
   }
}


class Spawn_Ammo_On_Destroyed extends When_Destroyed
{
   // automatically called by the engine when the game object this script is attached to is
   // destroyed
   public function OnDestroyed() {
    // spawn ammo
    }
}

Unity3D uses a component-based system by default. It is superb for creating game entities from a text file and dependency injection.

function createEnemy() {
   
   // extract AI type for enemy
   // definition is a custom structure holding parameters to create the enemy
   var aitypename = definition.ai;

   // AIType can be an interface or abstract class
   // you can create a component from a string or from a type
   var ai : AIType = this.gameObject.AddComponent(aitypename);
   ai.setup(definition.ai_settings);

   // set rule for enemy when it is destroyed
   this.gameObject.AddComponent(definition.when_destoryed); 
 

}

Those components could look like this

class AI_Scout extends AIType
{
  // called per update-frame on the game-object with this script
  public function Update() {
    // run Scout AI here
   }
}


class Spawn_Ammo_On_Destroyed extends When_Destroyed
{
   // automatically called by the engine when the game object this script is attached to is
   // destroyed
   public function OnDestroyed() {
    // spawn ammo
    }
}
Source Link
Extrakun
  • 2.7k
  • 4
  • 26
  • 36

Unity3D uses a component-based system by default. It is superb for creating game entities from a text file and dependency injection.

function createEnemy() {
   
   // extract AI type for enemy
   // definition is a custom structure holding parameters to create the enemy
   var aitypename = definition.ai;

   // AIType can be an interface or abstract class
   // you can create a component from a string or from a type
   var ai : AIType = this.gameObject.AddComponent(aitypename);
   ai.setup(definition.ai_settings);

   // set rule for enemy when it is destroyed
   this.gameObject.AddComponent(definition.when_destoryed); 
 

}

Those components could look like this

class AI_Scout extends AIType
{
  // called per update-frame on the game-object with this script
  public function Update() {
    // run Scout AI here
   }
}


class Spawn_Ammo_On_Destroyed extends When_Destroyed
{
   // automatically called by the engine when the game object this script is attached to is
   // destroyed
   public function OnDestroyed() {
    // spawn ammo
    }
}
Post Made Community Wiki