Ejemplo n.º 1
0
 public void getController(string entityType, Vector2 direction, float speed = 0)
 {
     if (direction == null)
     {
         direction = Vector2.zero;
     }
     rb2d = gameObject.GetComponent <Rigidbody2D>();
     if (rb2d == null)
     {
         rb2d = gameObject.AddComponent <Rigidbody2D>();
     }
     if (entityType != null)
     {
         if (entityType.Equals("player"))
         {
             controller = new PlayerController(this, speed);
         }
         else if (entityType.Equals("projectile"))
         {
             controller = new ProjectileController(this, direction, speed);
         }
         else if (entityType.Equals("powerup"))
         {
             controller = new PowerupController(this);
         }
         else if (entityType.Equals("enemy"))
         {
             controller = new EnemyController(this);
         }
     }
     else
     {
         if (gameObject.CompareTag(GameDefaults.Player()))
         {
             controller = new PlayerController(this, speed);
         }
         else if (gameObject.CompareTag(GameDefaults.Projectile()))
         {
             controller = new ProjectileController(this, direction, speed);
         }
         else if (gameObject.CompareTag(GameDefaults.Powerup()))
         {
             controller = new PowerupController(this);
         }
         else if (gameObject.CompareTag(GameDefaults.Enemy()))
         {
             controller = new EnemyController(this);
         }
     }
 }
Ejemplo n.º 2
0
 public void Start()
 {
     if (parent == null)
     {
         parent = gameObject;
     }
     if (entityType.Equals("powerup"))
     {
         Init(entityType, transform.position, new Vector2(), 0f, null);
     }
     if (!entityType.Equals("player"))
     {
         return;
     }
     controller = this.gameObject.GetComponent <EntityControllerInterface>();
     rb2d       = gameObject.GetComponent <Rigidbody2D>();
     if (rb2d == null)
     {
         rb2d = gameObject.AddComponent <Rigidbody2D>();
     }
     controller = new PlayerController(this, speed);
 }