private void Awake() { base.Awake(); playerKnockBackControl = transform.root.GetComponentInChildren(typeof(IKnockbackable)) as IKnockbackable; meleeAbilityStats = GetComponent <MeleeAbilityStats>(); meleeEffectCollider.enabled = false; }
private void Awake() { _health = GetComponent <Health>(); _knockback = GetComponent <IKnockbackable>(); _health.Damaged += OnDamaged; }
/// <summary> /// Unity callback. Called on object instantiation. /// </summary> void Awake() { Source = GetComponentInParent <Character>(); _damageable = GetComponentInParent <IDamageable>(); _knockbackable = GetComponentInParent <IKnockbackable>(); //_effect = GetComponent<ParticleSystem>(); //_soundEffect = GetComponent<AudioSource>(); gameObject.tag = Tags.Hitbox; switch (type) { case Type.Damageable: case Type.Shield: gameObject.layer = Layers.Hurtbox; break; default: gameObject.layer = Layers.Hitbox; break; } _colliders = GetComponents <Collider>(); foreach (Collider col in _colliders) { col.isTrigger = true; } }
/// <summary> /// Knocks the colliding GameObject away. Knockback is handled differently /// for entities than for typical Rigidbodies to avoid bugs. /// </summary> /// <param name="collision"> /// Collision holding information about colliding object. /// </param> protected virtual void Knockback(Collision collision) { if (KnockbackableMagnitude <= 0 || KnockbackMagnitude <= 0) { return; } Vector3 knockbackDir = GetKnockbackDirection(collision); IKnockbackable knockbackable = collision.gameObject.GetComponent <IKnockbackable>(); if (knockbackable != null) { knockbackable.Knockback(knockbackDir, KnockbackableMagnitude); } else { ApplyForceToRigidbody(collision, knockbackDir); } }
protected void OnTriggerEnter2D(Collider2D collision) { IDamageable damageable = (IDamageable)collision.transform.root.GetComponentInChildren(typeof(IDamageable)) as IDamageable; IKnockbackable knockbackable = (IKnockbackable)collision.transform.root.GetComponentInChildren(typeof(IKnockbackable)) as IKnockbackable; if (damageable != null) { if (collision.tag == "Enemy") { float baseDamage = meleeAbilityStats.GetDamage(); damageable.TakeDamage(baseDamage); } } if (knockbackable != null) { if (collision.tag == "Enemy") { } } /* * Player recoil */ if (attackSide == AttackSide.horizontal) { if (collision.tag == "Ground") { playerKnockBackControl.KnockbackStraight(-knockBackStraightDirection, knockbackPlayerAmount, AttackSide.horizontal); //print(-knockBackStraightDirection); } } if (attackSide == AttackSide.down) { //if (collision.tag == "Ground"){ // playerKnockBackControl.KnockbackStraight(-knockBackStraightDirection, knockbackPlayerAmount, AttackSide.down); //} } }
private void Awake() { unitKnockback = GetComponent <IKnockbackable>(); unitHealth = GetComponent <HealthComponent>(); }