protected void LateUpdate() { if(player == null || health == null) { player = EntityUtils.GetEntityWithTag("Player"); if(player == null) { return; } health = player.GetHealth(); if(health == null) { return; } } float current = health.CurrentHealth; float max = health.StartingHealth; float alpha = 1 - current / max; Color color = image.material.color; color.a = alpha * 0.65f; image.material.color = color; }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.CompareTag("Player")) { switch (type) { case PickupType.Health: //Do not use pickup if player cannot benefit from it - i.e. when they are at max health EntityHealth playerHealth = col.gameObject.GetComponent <EntityHealth>(); if (playerHealth.Health == playerHealth.MaxHealth) { return; } //Otherwise increase their HP col.gameObject.GetComponent <PlayerControllerScript>().HurtPlayer(-1 * indexOrPotency); break; case PickupType.Weapon: col.gameObject.GetComponent <PlayerControllerScript>().AddWeapon(indexOrPotency); break; case PickupType.Ability: //TODO: Change this if/when more than one ability is added to the game col.gameObject.GetComponent <PlayerControllerScript>().CanGlide = true; break; } Destroy(gameObject); } }
internal void TurnOnShield(string[] splitCode) { int id = int.Parse(splitCode[1]); EntityHealth target = network.GetPlayerOfID(id).GetComponent <EntityHealth>(); target.TurnOnShield(); }
public void OnCollisionEnter2D(Collision2D collision) { GameObject gameObj = collision.gameObject; EntityHealth entityHealth = gameObj.GetComponent <EntityHealth>(); if (entityHealth != null) { foreach (LayerMask layer in layersCanAffect) { if ((layer & 1 << gameObj.layer) == 1 << gameObj.layer) { if (canDamageEntities) { DealDamage(entityHealth, damage); } else { DealDamage(entityHealth, -damage); } Destroy(this.gameObject); } } } }
void Start() { entity = new EntityHealth(); entity.Health = 50; player = FindObjectOfType <PlayerHealth>().gameObject; }
public bool Hit(HitInfo hit) { if (!(hit.AttackType == AttackType.Nail || hit.AttackType == AttackType.NailBeam)) { return(false); } if (healthManager == null) { healthManager = GetComponentInParent <EntityHealth>(); } if (enemy == null) { enemy = GetComponentInParent <Enemy>(); } if (healthManager != null) { var validity = healthManager.IsValidHit(hit); if (validity == HitResult.Valid) { StartCoroutine(HitRoutine(hit)); } return(validity == HitResult.Valid); } else { StartCoroutine(HitRoutine(hit)); return(true); } }
private void Assert_Health(EntityHealth expected, EntityHealth actual) { Assert.AreEqual(expected.AggregatedHealthState, actual.AggregatedHealthState); Assert.AreEqual(expected.GetHealthEvaluationString(), actual.GetHealthEvaluationString()); if (expected.HealthEvents == null) { Assert.IsNull(actual.HealthEvents); } else { var expectedEvents = expected.HealthEvents.ToList(); var actualEvents = actual.HealthEvents.ToList(); Assert.AreEqual(expectedEvents.Count, actualEvents.Count); for (var index = 0; index < expectedEvents.Count; index++) { var expectedEvent = expectedEvents[index]; var actualEvent = actualEvents[index]; Assert.AreEqual(expectedEvent.SequenceNumber, actualEvent.SequenceNumber); Assert.AreEqual(expectedEvent.Property, actualEvent.Property); Assert.AreEqual(expectedEvent.Description, actualEvent.Description); Assert.AreEqual(expectedEvent.SourceId, actualEvent.SourceId); Assert.AreEqual(expectedEvent.HealthState, actualEvent.HealthState); Assert.AreEqual(expectedEvent.IsExpired, actualEvent.IsExpired); } } }
private void DoAbility(Collider other) { if ((network && network.IsHost()) || !network) { Vector3 position = other ? other.gameObject.transform.position : transform.position; EventController.FireEvent(new WorldVFXMessage(WorldSpaceVFX.WorldVFXType.bomb, position)); if (network) { network.SendWorldVFX(WorldSpaceVFX.WorldVFXType.bomb, position, -1, parent.GetIdOfAbilityBall(this)); } //First radius Collider[] cols = Physics.OverlapSphere(transform.position, lastRadius); foreach (Collider collider in cols) { TargetDummy t = collider.GetComponent <TargetDummy>(); EntityHealth enemy = collider.GetComponent <EntityHealth>(); float sqrDist = (collider.transform.position - transform.position).sqrMagnitude; if (sqrDist <= firstRadius * firstRadius) { if (t) { t.ShowHit(75); } else if (enemy) { DoBombDamage(enemy, 75); } } else if (sqrDist <= secondRadius * secondRadius) { if (t) { t.ShowHit(50); } else if (enemy) { DoBombDamage(enemy, 50); } } else if (sqrDist <= lastRadius * lastRadius) { if (t) { t.ShowHit(50); } else if (enemy) { DoBombDamage(enemy, 50); } } } SoundManager.PlaySoundAt("Bomb Explosion", transform.position); } base.TriggerAbility(); }
void Start() { sprite = GetComponent <SpriteRenderer>(); baseColor = sprite.color; hp = GetComponent <EntityHealth>(); charControl = GetComponent <Rigidbody2D>(); speedMultiplier = 1; }
// Start is called before the first frame update void Start() { health = GetComponent <EntityHealth>(); animator = GetComponent <Animator>(); rb = GetComponent <Rigidbody>(); bMoving = false; viewAngle = 40f; }
private void TryShoot() { if (Application.platform == RuntimePlatform.Android || Input.GetMouseButton(0)) { if (Time.time - _lastShot > _rateOfFire && _currentAmmoCount > 0) { Ray ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width * 0.5f, Screen.height * 0.5f)); RaycastHit hit; Physics.Raycast(ray, out hit); if (Application.platform != RuntimePlatform.Android || hit.transform.tag == "Damageable") { // this can me null if firing in sky on PC if (hit.collider) { Instantiate(_hitParticle, hit.point, Quaternion.identity); EntityHealth component = hit.collider.GetComponent <EntityHealth>(); if (component) { component.TakeDamage(_damage); } else { // Only spawn decal on non damageable entities (IE walls, ground) Instantiate(_decalPrefab, hit.point + hit.normal * A_LITTLE_FORWARD, Quaternion.LookRotation(-hit.normal)); } } _lastShot = Time.time; if (!_infiniteAmmoActivated) { CurrentAmmoCount--; } if (_currentAmmoCount == 0) { StartCoroutine("Reload"); } // Feedbacks // randomize pitch to avoid the sound so be all time the same _shotAudioSource.pitch = UnityEngine.Random.Range(1f, 1.1f); _shotAudioSource.PlayOneShot(_gunSound); _muzzleFlashAnimator.SetTrigger("Fire"); StartCoroutine(_cameraShake.Shake(_shakeDuration, _shakeMagnitude)); } } } if (_currentAmmoCount < _MaxAmmo) { if (Input.GetKeyDown(KeyCode.Space)) { // PC reload StartCoroutine("Reload"); } if (Input.acceleration.magnitude > _mobileAccelerationMagnitudeToReload) { // mobile reload StartCoroutine("Reload"); } } }
protected virtual void Awake() { //BossStage = 1; var bossImplType = ImplFinder.GetImplementationType <Boss_I>(); impl = (Boss_I)gameObject.AddComponent(bossImplType); entityHealth = GetComponent <EntityHealth>(); entityHealth.OnDeathEvent += OnDeath; }
public static void checkHealthOverflow(GameObject obj) { EntityHealth objHealth = obj.GetComponent <EntityHealth>(); if (objHealth.health > objHealth.maxHealth) { objHealth.health = objHealth.maxHealth; } }
void ProxyAwake() { weaverHealth = GetComponent <EntityHealth>(); hp = weaverHealth.Health; previousHP = weaverHealth.Health; weaverHealth.OnHealthChangeEvent += WeaverHealth_OnHealthChangeEvent; }
private void DisplayHealth(EntityHealth health) { SetSpritesActive(health.CurrentHealth < health.MaxHealth); float size = health.CurrentHealth / (float)health.MaxHealth; foregroundBar.localScale = new Vector3(size, 1f, 1f); foregroundBar.localPosition = new Vector3((size - 1f) / 2f, 0f, 0f); }
private void DoBombDamage(EntityHealth enemy, int damage) { enemy.TakeDamage(damage, IDofLastHit); if (enemy.GetHealth() - damage <= 0) { EventController.FireEvent(new TrackSuperlativeMessage(SuperlativeController.Superlative.HailMary, SuperlativeController.ConditionFlag.identity, Vector3.Distance(transform.position, GetComponent <BallRetrieval>().GetLastPos()), GetLastShotId())); } }
private void StartStage(Stage stage) { EntityHealth playerHealth = stage.PlayerEntity.GetComponent <EntityHealth>(); playerHealth.OnHealthChanged += UpdateHealth; EntityAttack playerAttack = stage.PlayerEntity.GetComponent <EntityAttack>(); playerAttack.OnDamageChanged += UpdateDamage; }
private void Shoot(Cell target) { if (target.FrontEntity == null) { return; } EntityHealth health = target.FrontEntity.GetComponent <EntityHealth>(); health.TakeDamage(GetDamage()); }
void Start() { entity = new EntityHealth(); entity.Health = 100; enemy = FindObjectsOfType <EnemyHealth>(); go = Instantiate(projectile, transform.position - new Vector3(0, 0.4f, 0), Quaternion.identity) as GameObject; ax_ = Instantiate(ax, transform.position, Quaternion.identity) as GameObject; anim = ax_.GetComponent <Animator>(); }
protected new void Awake() { base.Awake(); aiControllers = GetComponents <IEntityActionAIController>(); EntityHealth entityHealth = GetComponent <EntityHealth>(); if (entityHealth != null) { entityHealth.OnDeath += Die; } }
private void OnTriggerEnter2D(Collider2D collider) { if (collider.tag == "Factory") { EntityHealth factoryHealth = collider.GetComponent <EntityHealth>(); if (factoryHealth != null) { AudioSource.PlayClipAtPoint(AttackFactoryClip, Camera.main.transform.position); factoryHealth.ApplyDamage(DamageToFactory); Destroy(this.gameObject); } } }
private void OnTriggerEnter2D(Collider2D collider) { if (collider.gameObject == _owner || collider.tag == _teamTag) { return; } EntityHealth targetHealth = collider.GetComponent <EntityHealth>(); if (targetHealth != null) { targetHealth.ApplyDamage(Damage); HandleAttackType(collider.gameObject); } }
// Constructor protected Entity(ContentManager content, string path, Vector2 startPosition, ICollection <Entity> entities, ICollection <Block> terrain, ICollection <Bullet> bullets, float scale = 1, int health = 5, int movementspeed = 50) { sprite = new Sprite(content, path, startPosition, scale: scale); Entities = entities; Entities.Add(this); Position = startPosition; facing = Facing.Right; move = new Moving(movementspeed); collision = new Collision(terrain, entities, bullets); Health = new EntityHealth(health, content, this, scale); }
void GetEntityList() { if (enemies.Count == 0) { enemies = new List <EntityHealth>(); for (int i = 0; i < enemyParent.transform.childCount; i++) { enemies.Add(enemyParent.transform.GetChild(i).GetComponent <EntityHealth>()); } } if (allyParent.transform.childCount > 0) { player = allyParent.transform.GetChild(0).GetComponent <EntityHealth>(); } }
// Start is called before the first frame update void Start() { if (!player) { player = GameObject.FindGameObjectWithTag("Player"); } if (respawn.respawnPoint == null) { respawn.tempRespawnPoint = Instantiate(respawn.respawnPrefab, player.transform.position, Quaternion.identity); respawn.respawnPoint = respawn.tempRespawnPoint.transform; } playerHealth = player.GetComponent <EntityHealth>(); uim = GetComponent <UI_Manager>(); }
public override void TriggerAbilityPlayer(Collider other) { EntityHealth enemy = other.gameObject.GetComponent <EntityHealth>(); if (enemy) { enemy.TakeDamage(damage, IDofLastHit); if (enemy.GetHealth() - damage <= 0) { EventController.FireEvent(new TrackSuperlativeMessage(SuperlativeController.Superlative.HailMary, SuperlativeController.ConditionFlag.identity, Vector3.Distance(transform.position, GetComponent <BallRetrieval>().GetLastPos()), GetLastShotId())); } } base.TriggerAbility(); }
public static void Load() { PositionOffsetPath = new EntityPosition(0); RotationOffsetPath = new EntityRotation(0); NetworkableOffsetPath = new EntityNetworkable(0); PlayerFlagsPath = new EntityPlayerFlags(0); EntityTagPath = new EntityTag(0); EntityNamePath = new EntityName(0); PlayerNamePath = new PlayerName(0); EntityLayerPath = new EntityLayerPath(0); EntitySteamID = new EntitySteamID(0); EntityLifeState = new EntityLifeState(0); EntityPlayerModelFlags = new EntityPlayerModelFlags(0); ActiveItem = new PlayerActiveItem(0); BeltList = new PlayerBeltItemList(0); EntityHealth = new EntityHealth(0); }
public void Attack(Actors actor) { switch (actor) { case Actors.Player: animator.SetTrigger("EnemyDamage"); enemies[currentSelectedEnemy].DealDamage(player.damage); break; case Actors.Enemy: animator.SetTrigger("PlayerDamage"); if (enemies.Count > 0) { attacker = enemies[Random.Range(0, enemies.Count)]; player.DealDamage(attacker.damage); } break; } }
private GameObject GetClosestPlayer(Collider[] players) { int index = -1; float distance = float.MaxValue; Vector3 direction; float squareMag = -1; for (int i = 0; i < players.Length; i++) { if (nStoredData) { EntityHealth target = players[i].GetComponent <EntityHealth>(); if (target != null) { int playerId = target.MyID; if (nStoredData.GetTeam(playerId) == nStoredData.GetTeam(myGolfBall.GetLastShotId())) { continue; } } } direction = players[i].gameObject.transform.position - transform.position; if (Vector3.Dot(rb.velocity.normalized, direction.normalized) > 0) //Is in screen view { squareMag = Vector3.SqrMagnitude(direction); if (squareMag < distance) { index = i; distance = squareMag; } } } if (index >= 0) { return(players[index].gameObject); } else { return(null); } }
void OnTriggerEnter2D(Collider2D col) { if (tagsToIgnore.Contains(col.gameObject.tag) || col.isTrigger) { return; } if (col.CompareTag("Player")) { col.gameObject.GetComponent <PlayerControllerScript>().HurtPlayer(dmgAmount); } else { EntityHealth health = col.gameObject.GetComponent <EntityHealth>(); if (health != null) { health.ChangeHealth(-1 * dmgAmount); } } Destroy(gameObject); }
/// <summary> /// Serializes the object to JSON. /// </summary> /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="obj">The object to serialize to JSON.</param> internal static void Serialize(JsonWriter writer, EntityHealth obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.AggregatedHealthState, "AggregatedHealthState", HealthStateConverter.Serialize); if (obj.HealthEvents != null) { writer.WriteEnumerableProperty(obj.HealthEvents, "HealthEvents", HealthEventConverter.Serialize); } if (obj.UnhealthyEvaluations != null) { writer.WriteEnumerableProperty(obj.UnhealthyEvaluations, "UnhealthyEvaluations", HealthEvaluationWrapperConverter.Serialize); } if (obj.HealthStatistics != null) { writer.WriteProperty(obj.HealthStatistics, "HealthStatistics", HealthStatisticsConverter.Serialize); } writer.WriteEndObject(); }
protected void Update() { if(player == null || health == null) { player = EntityUtils.GetEntityWithTag("Player"); if(player == null) { return; } health = player.GetHealth(); } if(health.CurrentHealth <= (health.StartingHealth / 4)) { if(audioChannel == null || !audioChannel.IsPlaying) { audioChannel = audioManager.Play(audio); } } }
protected override void Awake() { base.Awake(); health = GetComponent<EntityHealth>(); }