private void OnDestroy() { onSetupDestroy.Invoke(this); if (_manager != null && _manager.IsCreated && _manager.Exists(_entity)) { _manager.DestroyEntity(_entity); } _manager = null; }
/// <summary> /// Register this Ship Collider /// </summary> /// <param name="entity">Associated Entity</param> /// <param name="manager">Entity manager</param> public void Register(Entity entity, EntityManager manager) { _manager = manager; _entity = entity; translation = new Translation { Value = transform.position }; rotation = new Rotation { Value = transform.rotation }; _manager.SetComponentData(_entity, translation); _manager.SetComponentData(_entity, rotation); _manager.AddComponentData(_entity, new ShipCollision { collisionMask = 0 }); _manager.AddComponentData(_entity, new ShipCollisionMask { belongsTo = belongsTo.value, collidesWith = collidesWith.value }); SetECSEnabled(true); onSetupComplete.Invoke(this); }
public void takeDamage(int damage) { if (isInvulnerable) { return; } currHitPoints -= damage; if (currHitPoints <= 0) { lives--; if (lives <= 0) { kill(); } else { currHitPoints = maxHitPoints; } onLifeLost.Invoke(getShipInfo()); } onDamaged.Invoke(getShipInfo()); }
private void kill() { onKilled.Invoke(getShipInfo()); Destroy(gameObject); }