protected void HitDetachableHitbox(AttachableHitbox user, DetachableHitbox receiver) { // Destroy projectile(or deflect projectile + hitstun the projectile too) MonoBehaviour.Destroy(receiver.gameObject); // Apply hitstun user.Character.GetComponent <CharacterCore>().ApplyHitstun(preset.HitstunDuration); }
protected void HitCharacter(DetachableHitbox user, CharacterCore receiver) { // Apply damage ShowFloatingText(receiver.transform, preset.Damage); receiver.TakeDamage(preset.Damage); receiver.ApplyHitstun(preset.HitstunDuration); receiver.GetComponent <CharacterMover>().SetVelocity(Vector2.up * preset.KnockupVelocity); Debug.Log("Hit character!"); }
protected DetachableHitbox InstantiateProjectile(Vector2 direction, float duration) { Transform projectileSpawnLocation = user.transform.Find(preset.ProjectileSpawnLocationName); DetachableHitbox projectile = MonoBehaviour.Instantiate(preset.ProjectilePrefab, projectileSpawnLocation.position, Quaternion.identity).GetComponent <DetachableHitbox>(); projectile.Initialise(user); projectile.AddEnterListener(HitCharacter); projectile.GetComponent <LinearProjectile>().SetParameters(direction, duration); return(projectile); }
private void OnTriggerStay2D(Collider2D collision) { if (!Active || !StayActive) { return; } if (ReferenceEquals(User, collision.gameObject)) // If I collided with the user, ignore { return; } bool successfulHit = false; if (attachedHitboxLayer.Contains(collision.gameObject)) { AttachableHitbox other = collision.GetComponent <AttachableHitbox>(); OnHitAttachableHitboxStay?.Invoke((T)this, other); HitAttachableHitboxStay(other); successfulHit = true; } else if (detachedHitboxLayer.Contains(collision.gameObject)) { DetachableHitbox other = collision.GetComponent <DetachableHitbox>(); if (GetInstanceID() > other.GetInstanceID()) { OnHitDetachableHitboxStay?.Invoke((T)this, other); // Apply Destroy() within the Effect HitDetachableHitboxStay(other); successfulHit = true; } } else if (characterLayer.Contains(collision.gameObject)) { CharacterCore other = collision.GetComponent <CharacterCore>(); OnHitCharacterStay?.Invoke((T)this, other); HitCharacterStay(other); successfulHit = true; } else if (groundLayer.Contains(collision.gameObject)) { OnHitGroundStay?.Invoke((T)this); HitGroundStay(); successfulHit = true; } // General behaviour if (successfulHit) { HitAnythingStay(); } }
protected virtual void HitDetachableHitboxStay(DetachableHitbox other) { }
protected virtual void HitDetachableHitboxEnter(DetachableHitbox other) { }
protected override void HitDetachableHitboxEnter(DetachableHitbox other) { GameObject hp = Instantiate(hitParticle); hp.transform.position = transform.position; }