Example #1
0
        public async void OnExternalTriggerStay2D(object source, ExternalTriggerStay2DEventArgs args)
        {
            // Can't take damage if frozen, invincible, or the game isn't playing
            if (IsFrozen || IsInvincible || !GameState.IsPlaying)
            {
                return;
            }

            HitBox2D hitBox = args.Other.GetComponent <HitBox2D>();

            // if hitbox exists and it is not mine then i need to take damage
            if (hitBox != null && hitBox.Owner != gameObject)
            {
                LivingObject livingObject = null;
                if (hitBox != null && hitBox.Owner != null)
                {
                    livingObject = hitBox.Owner.GetComponentInChildren <LivingObject>();
                }

                if (livingObject == null || livingObject != null && !livingObject.IsFrozen)
                {
                    await TakeDamageAsync(hitBox.Damage, hitBox);
                }
            }
        }
Example #2
0
        // ---

        void Awake()
        {
            livingObject    = GetComponent <LivingObject>();
            spriteRenderers = GetComponentsInChildren <SpriteRenderer>().ToList();

            colors = spriteRenderers.Select(sp => sp.color).ToList();


            livingObject.BeforeFreeze        += OnBeforeFreeze;
            livingObject.AfterFreeze         += OnAfterFreeze;
            livingObject.BeforeInvincibility += OnBeforeInvincibility;
            livingObject.AfterInvincibility  += OnAfterInvincibility;
            livingObject.BeforeDie           += OnBeforeDie;
        }