コード例 #1
0
ファイル: StompOnHead.cs プロジェクト: Connorlc/UnityProjects
 /// <summary>
 /// Init this instance.
 /// </summary>
 protected override void Init()
 {
     base.Init();
     damageInfo = new DamageInfo(1, DamageType.HEAD_STOMP, Vector3.zero);
     enemy = transform.parent.gameObject.GetComponent<Enemy>();
     if (enemy == null) enemy = GetComponent<Enemy>();
     if (enemy == null) Debug.LogWarning ("Unable to find the Enemy that this StompOnHead is attached to. Make sure your StompOnHead is a direct child of the enemy.");
 }
コード例 #2
0
 /// <summary>
 /// Pass damage from the given hazard to the CharacterHealth script.
 /// </summary>
 /// <param name="info">Information about the damage such as the hazard causing the damage.</param>
 public virtual void Damage(DamageInfo info)
 {
     if (enabled)
     {
         if (info.DamageType == DamageType.AUTO_KILL)
         {
             health.Kill();
         }
         else
         {
             health.Damage(info);
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// Init this instance, used for projectiles or hit boxes which are not children of a character.
 /// </summary>
 public virtual void Init(DamageInfo info, IMob character, Projectile projectile,  bool destroyOnEnemyHit, bool destroyOnSceneryHit)
 {
     this.character = character;
     if (character == null)
     {
         Debug.LogError ("A ProjectileHitBox (CharacterHitBox) must have a character");
     }
     myCollider = GetComponent<Collider2D>();
     if (myCollider == null)
     {
         Debug.LogError("A ProjectileHitBox (CharacterHitBox) must be on the same GameObject as a Collider2D");
     }
     myCollider.enabled = true;
     this.damageInfo = info;
     this.projectile = projectile;
     this.destroyOnSceneryHit = destroyOnSceneryHit;
     this.destroyOnEnemyHit = destroyOnEnemyHit;
 }
コード例 #4
0
ファイル: EnemyHurtBox.cs プロジェクト: kjyong1983/gwanjjack
 /// <summary>
 /// Pass damage from the given hazard to the Enemy script.
 /// </summary>
 /// <param name="info">Information about the damage such as the hazard causing the damage.</param>
 virtual public void Damage(DamageInfo info)
 {
     enemy.Damage(info);
 }
コード例 #5
0
 /// <summary>
 /// Initialise this instance.
 /// </summary>
 override public Movement Init(Character character)
 {
     this.character = character;
     damageInfo     = new DamageInfo(damageAmount, DamageType.PHYSICAL, Vector2.zero, character);
     return(this);
 }
コード例 #6
0
 /// <summary>
 /// A simple damage implementation.
 /// </summary>
 virtual protected void DoDamage(DamageInfo info)
 {
     OnDamaged(info);
 }
コード例 #7
0
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 public override void DoDamage(DamageInfo info)
 {
     isDeath = false;
 }
コード例 #8
0
 /// <summary>
 /// Do the damage movement
 /// </summary>
 public virtual void DoDamage(DamageInfo info)
 {
 }
コード例 #9
0
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 public virtual void HitCharacter(Character character, DamageInfo info)
 {
 }
コード例 #10
0
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 public override void HitCharacter(Character character, DamageInfo info)
 {
     for (int i = 0; i < statesToMovements.Length; i++)
     {
         if (statesToMovements[i].state == EnemyState.HITTING) currentMovement = statesToMovements[i].movement;
     }
     currentMovement.HitCharacter(character, info);
 }
コード例 #11
0
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 public override void HitCharacter(Character character, DamageInfo info)
 {
     if (bounceOnHit) speed *= -1;
 }
コード例 #12
0
 /// <summary>
 /// Init this instance, this should be called by the attack system during Start();
 /// </summary>
 override public void Init(DamageInfo info)
 {
     base.Init(info);
     hitMobs = new List <IMob>();
 }
コード例 #13
0
 /// <summary>
 /// Do the death movement
 /// </summary>
 public override void DoDeath(DamageInfo info)
 {
     for (int i = 0; i < statesToMovements.Length; i++)
     {
         if (statesToMovements[i].state == EnemyState.DEAD) currentMovement = statesToMovements[i].movement;
     }
     currentMovement.DoDeath(info);
 }
コード例 #14
0
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 override public void DoDamage(DamageInfo info)
 {
     originalHeight = enemy.Transform.position.y;
     // Bobble
     enemy.SetVelocityY(initialBobbleVelocity);
 }
コード例 #15
0
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 override public void HitCharacter(Character character, DamageInfo info)
 {
 }
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 override public void DoDamage(DamageInfo info)
 {
     isDeath = false;
 }
コード例 #17
0
 /// <summary>
 /// Initialise this instance.
 /// </summary>
 override public Movement Init(Character character)
 {
     AssignReferences(character);
     damageInfo = new DamageInfo(damageAmount, DamageType.HEAD_STOMP, Vector2.zero, character);
     return(this);
 }
コード例 #18
0
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 override public void DoDamage(DamageInfo info)
 {
     SetUpExplosionForce(info);
     this.isDeath = false;
 }
コード例 #19
0
 /// <summary>
 /// Start the damage movement.
 /// </summary>
 /// <param name="info">Info.</param>
 override public void Damage(DamageInfo info, bool isDeath)
 {
     DoBobble();
     this.isDeath = isDeath;
 }
コード例 #20
0
ファイル: EnemyMovement.cs プロジェクト: kjyong1983/gwanjjack
 /// <summary>
 /// Do the damage movement
 /// </summary>
 virtual public void DoDamage(DamageInfo info)
 {
 }
コード例 #21
0
 /// <summary>
 /// Called when the character hits an enemy.
 /// </summary>
 /// <param name="enemy">Enemy that was hit.</param>
 /// <param name="info">Damage info.</param>
 virtual public void HitEnemy(IMob enemy, DamageInfo info)
 {
     // We don't do anything here, but other attacks might
 }
コード例 #22
0
ファイル: EnemyMovement.cs プロジェクト: kjyong1983/gwanjjack
 /// <summary>
 /// Do the death movement
 /// </summary>
 virtual public void DoDeath(DamageInfo info)
 {
 }
コード例 #23
0
 /// <summary>
 /// Do the death movement
 /// </summary>
 public virtual void DoDeath(DamageInfo info)
 {
 }
コード例 #24
0
ファイル: EnemyMovement.cs プロジェクト: kjyong1983/gwanjjack
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 virtual public void HitCharacter(Character character, DamageInfo info)
 {
 }
コード例 #25
0
ファイル: Hazard.cs プロジェクト: Connorlc/UnityProjects
 /// <summary>
 /// Initialise this instance.
 /// </summary>
 protected virtual void Init()
 {
     damageInfo = new DamageInfo(damageAmount, damageType, transform.position);
     #if UNITY_EDITOR
     if (!damageCharacters && !damageEnemies) Debug.LogWarning("Hazard does not damage enemies or characters.");
     #endif
 }
コード例 #26
0
 /// <summary>
 /// Start the damage movement.
 /// </summary>
 /// <param name="info">Info.</param>
 override public void Damage(DamageInfo info, bool isDeath)
 {
     animationTimer = animationLength;
     this.isDeath   = isDeath;
 }
コード例 #27
0
        /// <summary>
        /// Coroutine to destory this object. You could override if you didn't want to destory
        /// for example if you have a pooling system.
        /// </summary>
        /// <param name="info">Damage info.</param>
        virtual protected IEnumerator DestroyAfterDelay(DamageInfo info)
        {
            yield return(new WaitForSeconds(destroyDelay));

            GameObject.Destroy(gameObject);
        }
コード例 #28
0
 /// <summary>
 /// Called when the enemy hits the character.
 /// </summary>
 /// <param name="character">Character.</param>
 /// <param name="info">Damage info.</param>
 public override void HitCharacter(Character character, DamageInfo info)
 {
 }
コード例 #29
0
 /// <summary>
 /// Do the death movement
 /// </summary>
 public override void DoDeath(DamageInfo info)
 {
     isDeath = true;
     if (destroyDelay > 0) StartCoroutine(DestroyAfterDelay());
 }
コード例 #30
0
 /// <summary>
 /// Do the death movement
 /// </summary>
 public override void DoDeath(DamageInfo info)
 {
     // Bobble
     enemy.SetVelocityY(initialBobbleVelocity);
     enemy.characterCanFall = false;
     if (destroyDelay > 0) StartCoroutine(DestroyAfterDelay());
 }
コード例 #31
0
 /// <summary>
 /// Kills all characters.
 /// </summary>
 protected void KillAllCharacters()
 {
     DamageInfo info = new DamageInfo(0, DamageType.TIME_EXPIRED, Vector2.zero);
     foreach (CharacterHealth c in FindObjectsOfType<CharacterHealth>())
     {
         c.Kill(info);
     }
     killSent = true;
 }
コード例 #32
0
        /// <summary>
        /// Start the damage movement.
        /// </summary>
        /// <param name="info">Info.</param>
        override public void Damage(DamageInfo info, bool isDeath)
        {
            int tmpAnimationIndex = -1;

            this.isDeath = isDeath;
            if (isDeath)
            {
                // Find a match
                for (int i = 0; i < deathAnimations.Count; i++)
                {
                    if (deathAnimations[i].damageType == info.DamageType)
                    {
                        tmpAnimationIndex = i;
                        animationTimer    = deathAnimations[i].animationTime;
                        break;
                    }
                }
                // No match try to find type == NONE
                for (int i = 0; i < deathAnimations.Count; i++)
                {
                    if (deathAnimations[i].damageType == DamageType.NONE)
                    {
                        tmpAnimationIndex = i;
                        animationTimer    = deathAnimations[i].animationTime;
                        break;
                    }
                }
            }
            else
            {
                // Find a match
                for (int i = 0; i < damageAnimations.Count; i++)
                {
                    if (damageAnimations[i].damageType == info.DamageType)
                    {
                        tmpAnimationIndex = i;
                        animationTimer    = damageAnimations[i].animationTime;
                        break;
                    }
                }
                // No match try to find type == NONE
                for (int i = 0; i < damageAnimations.Count; i++)
                {
                    if (damageAnimations[i].damageType == DamageType.NONE)
                    {
                        tmpAnimationIndex = i;
                        animationTimer    = damageAnimations[i].animationTime;
                        break;
                    }
                }
            }
            if (tmpAnimationIndex != -1)
            {
                currentAnimation = tmpAnimationIndex;
            }
            else
            {
#if UNITY_EDITOR
                Debug.LogWarning(string.Format("Couldn't find a damage/death animation for the given damage type ({0}). Use DamageType.NONE to specify a default.", info.DamageType));
#endif
                currentAnimation = 0;
            }
        }
コード例 #33
0
 /// <summary>
 /// Do the damaged movement
 /// </summary>
 public override void DoDamage(DamageInfo info)
 {
     originalHeight = enemy.Transform.position.y;
     // Bobble
     enemy.SetVelocityY(initialBobbleVelocity);
 }
コード例 #34
0
 /// <summary>
 /// Kills the character.
 /// </summary>
 virtual public void Kill(DamageInfo info)
 {
     health = 0;
     DoDeath(info);
 }
コード例 #35
0
        /// <summary>
        /// Does a death action.
        /// </summary>
        /// <param name="action">Action.</param>
        virtual protected IEnumerator DoDeathAction(DeathAction action, DamageInfo info)
        {
            // Wait...
            if (action.delay > 0)
            {
                yield return(new WaitForSeconds(action.delay));
            }
            // Then act
            switch (action.actionType)
            {
            case DeathActionType.DESTROY_CHARACTER:
                Destroy(character.gameObject);
                break;

            case DeathActionType.RESPAWN:
                health = startingHealth;
                dying  = false;
                LevelManager.Instance.Respawn(character);
                break;

            case DeathActionType.RELOAD_SCENE:
                                        #if !UNITY_4_6 && !UNITY_4_7 && !UNITY_5_1 && !UNITY_5_2
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
                                        #else
                Application.LoadLevel(Application.loadedLevel);
                                        #endif
                break;

            case DeathActionType.LOAD_ANOTHER_SCENE:
                                        #if !UNITY_4_6 && !UNITY_4_7 && !UNITY_5_1 && !UNITY_5_2
                LevelManager.PreviousLevel = SceneManager.GetActiveScene().name;
                SceneManager.LoadScene(action.supportingData);
                                        #else
                LevelManager.PreviousLevel = Application.loadedLevelName;
                Application.LoadLevel(action.supportingData);
                                        #endif
                break;

            case DeathActionType.SEND_MESSAGE:
                action.supportingGameObject.SendMessage(action.supportingData, SendMessageOptions.DontRequireReceiver);
                break;

            case DeathActionType.CLEAR_RESPAWN_POINTS:
                if (LevelManager.Instance != null)
                {
                    LevelManager.Instance.ClearRespawns();
                }
                break;

            case DeathActionType.RESET_DATA:
                foreach (Persistable persistable in action.supportingGameObject.GetComponents <Persistable>())
                {
                    persistable.ResetSaveData();
                }
                break;

            case DeathActionType.RESET_SCORE:
                ScoreManager.GetInstanceForType(action.supportingData).ResetScore();
                break;
            }
        }
コード例 #36
0
 /// <summary>
 /// A simple destroy implementation.
 /// </summary>
 virtual protected void DoDestroy(DamageInfo info)
 {
     GetComponent <Collider2D>().enabled = false;
     OnDestroyed(info);
     StartCoroutine(DestroyAfterDelay(info));
 }