public void DealDamage() { if (CurrentTarget != null) { CurrentTarget.GetComponent <IDamagable>().TakeDamage(Damage, transform, IsCrit()); } }
public void OnDealDamage() { switch (currentState) { case EnemyState.WALKING: break; case EnemyState.ATTACK_PLAYER: HealthLogic playerHealth = CurrentTarget.GetComponent <HealthLogic>(); playerHealth.OnReceiveDamage(attackDamage); if (playerHealth.health <= 0) { SetState(EnemyState.WALKING); return; } if (transform.position.DistanceGreaterThan(playerAttackDistance, CurrentTarget.position)) { SetState(EnemyState.CHASING); } break; case EnemyState.ATTACK_BASE: baseHealth?.OnReceiveDamage(attackDamage); break; case EnemyState.CHASING: break; case EnemyState.DEAD: break; } }
public override void Shoot() { if (CurrentTarget != null) { CurrentTarget.GetComponent <Enemy>().TakeDamage(damage); } SoundEffectManager.PlaySound("Shoot"); }
/// <summary> /// Выстрел /// </summary> /// <returns></returns> new public IEnumerator Shoot() { if (CurrentTarget != null) { isShoot = true; CurrentTarget.GetComponent <Enemy>().SetDamage(TowerDamage); yield return(new WaitForSeconds(DelayBetweenShots)); isShoot = false; } }
//-------------------------------------- // Redefined Methods //-------------------------------------- /// <summary> /// Dos something when get the goal. /// </summary> public override void doSomethingWhenGetTheGoal() { base.doSomethingWhenGetTheGoal(); //when an enemy get the goal catchs a crystal CrystalCell cc = CurrentTarget.GetComponent <CrystalCell>(); //enemy catchs crystal if (cc != null) { cc.catchCrystal(this); Destroy(this.gameObject); } }
//whileCasting will remove the targeting and call the ExeEffect() as needed to ensure each enemy within the space is being effected correctly public static WhileCasting() { //deavtivate the targeting object from the player //ensure the spell effects each of the targets within the area of effect for the spell for(int i = 0; i < targets.Length; i++) { CurrentTarget = targets[i]; CurTrgtHealth = CurrentTarget.GetComponent<Attributes>().Health; CurTrgtEnergy = CurrentTarget.GetComponent<Attributes>().Energy; CurTrgtRigidBody = CurrentTarget.GetComponent<RigidBody>(); /*add others as needed*/ ExeEffect(); } }
// Update is called once per frame void Update() { if (this.CurrentTarget != null && IsAnimatingAttack()) { Util.RotateToward(transform, CurrentTarget.position, false, 0); } if (CurrentTarget && CurrentTarget.GetComponent <UnitHealth>().GetCurrentHP() <= 0) { CurrentTarget = null; } //We need to check, whether the npc who blocked by wall, is still being blocked or not. //If the last lastHitWallTime is 1/3 second ago, then it means the npc has not been blocked anymore //so we reset the HitWallTimeLength & BlockByWall if (BlockByWall && (Time.time - lastHitWallTime >= 1f)) { BlockByWall = false; HitWallTimeLength = 0; } }
private void Attack() { #region Attacking the player if (playerRef.Equals(CurrentTarget)) { //Get the health component and f**k him up if (!ranged) { playerRef.GetComponent <HealthManager>().Damage(); currState = States.PostAttck; } else { Shoot(); } return; } #endregion #region Attacking a lover AI loverRef = CurrentTarget.GetComponent <AI>(); if (!ranged) { loverRef.conversionTimer += Time.deltaTime; } else { Shoot(); } //Ranged attacks are managed by the projectile script if (loverRef.conversionTimer >= conversionTime) { //Attack loverRef.ConvertToHater(); loverRef.conversionTimer = 0f; CurrentTarget = null; currState = States.Patrol; } #endregion }
private void Attack() { //if have target, but can't see it if (!CanSeeTarget()) { } //Move to target float distance = Util.DistanceOfCharactersXZ(this.controller, CurrentTarget.GetComponent <CharacterController>()); //If distance not close enough to attack if (distance > AttackRadius) { Util.MoveTowards(transform, CurrentTarget.position, this.controller, true, false, MovementSpeed, 0); animation.CrossFade(RunAnimation); } else { ShootOnce(false); } }
private bool CanSeeTarget() { if (!controller) { Debug.Log("Controller is null!"); } if (!CurrentTarget.GetComponent <CharacterController>()) { Debug.Log("currentTarget.Controller is null: " + CurrentTarget.name); } if (Util.DistanceOfCharactersXZ(controller, CurrentTarget.GetComponent <CharacterController>()) > AttackRadius) { return(false); } if (Physics.Linecast(transform.position, CurrentTarget.position, terrainLayer)) { return(false); } return(true); }
/// <summary> /// Calculate the direction for fallback. /// Basically the direction is away from currentTarget, but have a random angular offset (-30,30) /// </summary> private void CalculateFallbackParameter() { if (CurrentTarget) { enemyDistance = CurrentTarget.GetComponent <CharacterController>() ? Util.DistanceOfCharactersXZ(controller, CurrentTarget.GetComponent <CharacterController>()) : Util.Distance_XZ(CurrentTarget.position, transform.position); if (enemyDistance <= AlertRadius) { //Redirect fallback direction in every <RedirectFallbackTimeout> seconds if (LastTimeRedirectionFallback <= 0 || (Time.time - LastTimeRedirectionFallback) >= RedirectFallbackTimeout) { Vector3 direction = transform.position - CurrentTarget.transform.position; //plus random factor Quaternion rotation = Quaternion.LookRotation(direction); rotation = Util.RotateAngleYAxis(rotation, Random.Range(-30f, 30f)); fallBackDirection = rotation * Vector3.forward; Debug.DrawRay(transform.position, fallBackDirection, Color.red); //Debug.Log("Redirect at:" + Time.time); LastTimeRedirectionFallback = Time.time; } } } }