/// <summary>
        /// Initialise this movement and return a reference to the ready to use movement.
        /// </summary>
        override public EnemyMovement Init(Enemy enemy)
        {
            this.enemy = enemy;
            EnemyHurtBox hurtBox = enemy.gameObject.GetComponentInChildren <EnemyHurtBox> ();

            if (hurtBox)
            {
                hurtCollider = hurtBox.GetComponent <Collider2D>();
            }
            else
            {
                Debug.LogError("Hiding enemy has no hurt box so there is nothing to disable on hide.");
            }
            if (removeHazards)
            {
                Hazard hazard = enemy.gameObject.GetComponentInChildren <Hazard> ();
                if (hazard)
                {
                    hazardCollider = hazard.GetComponent <Collider2D>();
                }
                else
                {
                    Debug.LogError("Hiding enemy has 'remove hazards' checked has no Hazard was found.");
                }
            }
            return(this);
        }
Example #2
0
 /// <summary>
 /// Do the actual hit.
 /// </summary>
 /// <param name="other">Other.</param>
 virtual protected void DoHit(Collider2D other)
 {
     // If we are a one shot and have already fired we can't cause damage any more, if not continue
     if (!oneShot || !hasFired)
     {
         if (damageCharacters)
         {
             CharacterHurtBox hurtBox = other.gameObject.GetComponent <CharacterHurtBox>();
             if (hurtBox != null)
             {
                 damageInfo.Direction  = transform.position - other.transform.position;
                 damageInfo.DamageType = damageType;
                 damageInfo.Amount     = damageAmount;
                 hurtBox.Damage(damageInfo);
                 hasFired = true;
             }
         }
         if (damageEnemies)
         {
             EnemyHurtBox enemyHurtBox = other.gameObject.GetComponent <EnemyHurtBox>();
             if (enemyHurtBox != null)
             {
                 damageInfo.Direction  = transform.position - other.transform.position;
                 damageInfo.DamageType = damageType;
                 damageInfo.Amount     = damageAmount;
                 enemyHurtBox.Damage(damageInfo);
                 hasFired = true;
             }
         }
     }
 }
        /// <summary>
        /// Init this enemy AI.
        /// </summary>
        override public void Init(Enemy enemy)
        {
            base.Init(enemy);
            // Listen to damage events and if we get them hide
            enemy.Damaged  += EnemyDamaged;
            enemy.Collided += EnemyDamaged;

            // If we need it try and find a charge movement
            if (useChargeState)
            {
                EnemyMovement_Distributor distributor = enemy.GetComponentInChildren <EnemyMovement_Distributor>();
                if (distributor != null)
                {
                    foreach (EnemyStateToMovement estm in distributor.statesToMovements)
                    {
                        if (estm.state == EnemyState.CHARGING)
                        {
                            chargeMovement = estm.movement;
                            break;
                        }
                    }
                }
                else
                {
                    chargeMovement = enemy.GetComponentInChildren <EnemyMovement_Charge>();
                }
            }
            // Try to find a cahracter hurt box so we can collect coins and damage other enemies
            characterHitBox = GetComponentInChildren <CharacterHitBox>();
            if (characterHitBox != null)
            {
                // Don't hit ourselves
                EnemyHurtBox myHurtBox = enemy.GetComponentInChildren <EnemyHurtBox>();
                if (myHurtBox != null)
                {
                    Physics2D.IgnoreCollision(characterHitBox.GetComponent <Collider2D>(), myHurtBox.GetComponent <Collider2D>());
                }
                // Init hit box
                characterHitBox.Init(new DamageInfo(1, DamageType.PHYSICAL, Vector2.zero));
            }
        }
Example #4
0
        /// <summary>
        /// Shows any high level warnings which may suggest misconfigured characters.
        /// </summary>
        virtual protected void ShowWarnings()
        {
            GUILayout.Space(10);
            GUI.color = Color.white;
            GUILayout.Label("Warnings and Helpers", EditorStyles.boldLabel);
            // Enemy has a hazard
            EnemyHazard hazard = ((Enemy)target).gameObject.GetComponentInChildren <EnemyHazard>();

            if (hazard == null)
            {
                Hazard plainHazard = ((Enemy)target).gameObject.GetComponentInChildren <Hazard>();

                if (plainHazard == null)
                {
                    EditorGUILayout.HelpBox("This enemy does not have an EnemyHazard attached. It won't be able to damage the character.", MessageType.Info);
                    if (GUILayout.Button("Add a Hazard"))
                    {
                        AddHazard();
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("This enemy has a Hazard but not an EnemyHazard attached. It won't be informed that it has hit a character.", MessageType.Warning);
                }
            }
            // Hazard has a collider
            else
            {
                if (hazard.GetComponent <Collider2D>() == null)
                {
                    EditorGUILayout.HelpBox("The Hazard does not have a collider attached. It won't be able to damage the character.", MessageType.Warning);
                    if (GUILayout.Button("Add a BoxCollider2D"))
                    {
                        AddCollider(hazard);
                    }
                }
            }
            // Hurt box
            EnemyHurtBox hurtBox = ((Enemy)target).gameObject.GetComponentInChildren <EnemyHurtBox>();

            if (hurtBox == null)
            {
                EditorGUILayout.HelpBox("This enemy does not have an EnemyHurtBox attached. The character wont be able to damage it.", MessageType.Info);
                if (GUILayout.Button("Add a HurtBox"))
                {
                    AddHurtBox();
                }
            }
            // Hurt box has a collider
            else
            {
                if (hurtBox.GetComponent <Collider2D>() == null)
                {
                    EditorGUILayout.HelpBox("The HurtBox does not have a collider attached. The character wont be able to damage it", MessageType.Warning);
                    if (GUILayout.Button("Add a BoxCollider2D"))
                    {
                        AddCollider(hurtBox);
                    }
                }
            }
        }