private void ThrowWeapon(DeathComponent death) { if (death.Weapon == null) { return; } var colliders = death.Weapon.GetComponentsInChildren <Collider2D>(); if (colliders != null && colliders.Length > 0) { foreach (var collider in colliders) { collider.isTrigger = false; } } death.Weapon.SetParent(null, true); DOTween.Sequence() .Append(death.Weapon.DOMove(death.Weapon.position + Vector3.up, 0.4f)) .Join(DOTween.Sequence() .Append(death.Weapon.DORotate(Vector3.forward * 360, .2f, RotateMode.WorldAxisAdd)) .Append(death.Weapon.DORotate(Vector3.forward * 0, .2f, RotateMode.WorldAxisAdd))) .Append(death.Weapon.DORotate(Vector3.forward * 180, .2f, RotateMode.WorldAxisAdd)) .Join(death.Weapon.DOMove(death.Weapon.position, 0.2f)) .Play(); }
public void Construct(IDefensiveStats stats, GameplayEventInt healthChangeEvent, int startingHealth, DeathComponent deathComponent) { _stats = stats; _healthChangeEvent = healthChangeEvent; SetHealth(startingHealth); _deathComponent = deathComponent; }
protected override void OnUpdate() { for (int i = 0; i < data.Length; i++) { DeathComponent death = data.death[i]; Entity entity = data.entities[i]; death.timer -= Time.deltaTime; if (death.timer < 0) { PostUpdateCommands.DestroyEntity(entity); if (EntityManager.HasComponent <Transform>(entity)) { gameObjectsToDestroy.Add(EntityManager.GetComponentObject <Transform>(entity).gameObject); } } data.death[i] = death; } for (int i = 0; i < gameObjectsToDestroy.Count; i++) { Object.Destroy(gameObjectsToDestroy[i]); } gameObjectsToDestroy.Clear(); }
private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Enemy")) { DeathComponent deathComponent = other.GetComponent <DeathComponent>(); if (deathComponent) { deathComponent.Death(); } } }
private void Start() { mediator = FindObjectOfType <PlayerController>().Mediator; HealthBar = GetComponentInChildren <Slider>(); health = maxHealth; health = health * GameManager.INSTANCE.difficultyMultipier; deathComponent = GetComponent <DeathComponent>(); AmountOfDamage = health / 3 * GameManager.INSTANCE.difficultyMultipier; }
private void CheckForDead() { foreach (var health in FindObjectsOfType <HealthComponent>()) { if (health.Health > 0) { continue; } DeathComponent death = health.GetComponentInChildren <DeathComponent>(); if (death == null) { continue; } if (death.DeathSprite == null) { Debug.LogWarning("Death sprite not set"); continue; } SpriteRenderer spriteRenderer = death.GetComponent <SpriteRenderer>(); if (spriteRenderer == null) { Debug.LogWarning("Shouldn't happen"); continue; } if (spriteRenderer.sprite == death.DeathSprite) { continue; // Done with this one } if (health.transform.name.Contains("Huge")) { _hugeGuyScream.PlayMutated(); Camera.main.transform.DOShakePosition(1.5f, 0.4f, 40, 0, false, true); } else { _deathSound.PlayMutated(); } spriteRenderer.sprite = death.DeathSprite; SwitchParticles(health.GetComponentsInChildren <ParticleSystem>()); if (!health.IsOutOfBounds) { ThrowWeapon(death); } } }
/// <summary> /// Awake /// </summary> protected void Awake() { Health = GetComponent <HealthComponent>(); Death = GetComponent <DeathComponent>(); AudioSource = GetComponent <AudioSource>(); }
public void Start() { animController = GetComponent <AnimController>(); deathComponent = GetComponent <DeathComponent>(); }
protected override void OnUpdate() { Entities.ForEach((Entity entity, ref IDComponent _outerID, ref Translation _translation, ref HasTarget _hasTarget, ref AttackComponent _attack, ref WeaponComponent _weapon, ref StateComponent _state) => { ComponentDataFromEntity <Translation> allTranslations = GetComponentDataFromEntity <Translation>(true); ComponentDataFromEntity <DeathComponent> allDead = GetComponentDataFromEntity <DeathComponent>(true); DeathComponent dead = allDead[_hasTarget.targetEntity]; if (_hasTarget.targetEntity != Entity.Null || !dead.isDead) { Translation targetTranslation = allTranslations[_hasTarget.targetEntity]; if (World.DefaultGameObjectInjectionWorld.EntityManager.Exists(_hasTarget.targetEntity) && _attack.range >= math.distance(_translation.Value, targetTranslation.Value) && _attack.isAttacking == true) { _attack.timer -= UnityEngine.Time.deltaTime; if (_attack.timer < 0) { IDComponent attackerID = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData <IDComponent>(entity); if (isDebug) { Debug.Log("Attack!"); } IDComponent targetID = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData <IDComponent>(_hasTarget.targetEntity); //GameController.Instance.DamageUnit(attackerID.id, targetID.id, _weapon.damage, GameController.damageType.Physical); _attack.timer = 10 / _attack.nrOfAttacks; float dmg = _weapon.damage; int outerID = _outerID.id; int newState = 1; Entities.ForEach((Entity innerEntity, ref IDComponent _innerID, ref HealthComponent _health, ref DeathComponent _death) => { if (targetID.id == _innerID.id) { if (isDebug) { Debug.Log(outerID + " hits " + _innerID.id + " with " + dmg + " damage"); } _health.health -= dmg; if (isDebug) { Debug.Log(_innerID.id + " has " + _health.health + " health left"); } if (_health.health <= 0) { _death.isDead = true; dead.isDead = true; newState = 0; if (isDebug) { Debug.Log(_innerID.id + " has died in combat"); } } PostUpdateCommands.AddComponent(innerEntity, new DoNotTarget { }); } }); if (newState == 0) { _state.state = 0; } if (dead.isDead) { if (isDebug) { Debug.Log("combat removing hastarget"); } Debug.Log("combat going idle"); PostUpdateCommands.AddComponent(entity, new IdleComponent { }); PostUpdateCommands.RemoveComponent(entity, typeof(HasTarget)); } } } } else { _state.state = 0; Debug.Log(_outerID + " has no target going idle"); } }); }