private void Awake() { _body = new AgentBody(); _physics = new AgentPhysics(transform, GetComponent <Rigidbody2D>(), this); _state = new StateMachine(); _animation = new AgentAnimation(this, GetComponent <SkeletonAnimation>()); _groundcheck = GetComponent <GroundCheck>(); _stats = new AgentStats(this); _agentSkills = GetComponent <AgentSkills>(); _health = GetComponent <AgentHealth>(); _state.ChangeState(new GroundedState(this)); if (tag == "Player") { DeathManager.Player = this; } else { if (DeathManager.Enemies == null) { DeathManager.Enemies = new List <Agent>(); } DeathManager.Enemies.Add(this); } }
// for attacking private void OnTriggerEnter(Collider other) { if (inDamageState) { AgentHealth health = other.GetComponentInParent <AgentHealth>(); Agent agent = other.GetComponentInParent <Agent>(); if (agent != null && health != null) { if (agent.CurrentState.GetType() != typeof(Blocking) && agent.CurrentState.GetType() != typeof(Rolling)) { // check to make sure not hitting self, multi-hitting one agent, or hitting someone with the same tag if (!hitAgents.Contains(health) && !transform.IsChildOf(health.transform) && !transform.root.CompareTag(health.tag)) { health.Damage(stats.damage * damageModifier, transform.position, MeleeStats.knockbackForce); hitAgents.Add(health); AudioManager.instance.PlaySoundAtPosition("Sword Hit", transform.position); //PoolManager.Instance.GetObjectFromPoolWithLifeTime(PoolManager.PoolTag.Blood, other.ClosestPoint(transform.position), Quaternion.identity, 3f); } } else { print("Attack Blocked"); ExitDamageState(); AudioManager.instance.PlaySoundAtPosition("Sword Block", transform.position); //PoolManager.Instance.GetObjectFromPoolWithLifeTime(PoolManager.PoolTag.Spark, other.ClosestPoint(transform.position), Quaternion.identity, 1f); } } } }
private void OnTriggerEnter(Collider other) { AgentHealth health = other.GetComponentInParent <AgentHealth>(); Agent agent = other.GetComponentInParent <Agent>(); if (agent != null) { if (agent.CurrentState.GetType() != typeof(Blocking)) { if (!hitHealths.Contains(health)) { health.Damage(damage * damageModifier, transform.position, knockbackForce); hitHealths.Add(health); } } else { print("Projectile Blocked"); AudioManager.instance.PlaySoundAtPosition("Sword Block", transform.position); //PoolManager.Instance.GetObjectFromPoolWithLifeTime(PoolManager.PoolTag.Spark, other.ClosestPoint(transform.position), Quaternion.identity, 1f); } } AudioManager.instance.PlaySoundAtPosition(impactSoundName, transform.position); Destroy(gameObject); }
void Update() { if (agent.health.IsDead) { return; } nextAttack -= Time.deltaTime; if (DoAttack && nextAttack < 0) { agent.animator.SetTrigger("slice"); DoAttack = false; nextAttack = attackRate; AgentHealth target = FindAttackTarget(); if (target != null) { bool wasDead = target.IsDead; target.Health -= damage; if (Globals.player.gameObject == this.gameObject && target.IsDead && !wasDead) { Globals.PlayerKilledAgentTime = Time.time; } Vector2 pos = 0.5f * (target.transform.position.XY() + this.transform.position.XY()); StartCoroutine(Tools.CreateParticleEffect(pfSlice, pos)); } } }
void Start() { animator = GetComponent <Animator>(); cc2 = (CircleCollider2D)this.collider2D; ah = GetComponent <AgentHealth>(); goal = Home; }
void Awake() { animator = GetComponent <Animator>(); move = GetComponent <AgentMove>(); health = GetComponent <AgentHealth>(); carry = GetComponent <AgentCarry>(); slice = GetComponent <AgentSlice>(); }
void OnTriggerEnter2D(Collider2D collider) { GameObject otherObject = collider.gameObject; if (otherObject.GetComponent <Attacker>() != null) { AgentHealth healthScript = otherObject.GetComponent <AgentHealth>(); healthScript.TakeDamage(damage); Destroy(gameObject); } }
/// <summary> /// Used for initialization /// </summary> void Awake() { // retrieve necessary components myHealth = GetComponent <AgentHealth>(); mySpriteRenderer = GetComponent <SpriteRenderer>(); myBehavior = GetComponent <PursueAndAttack>(); // initialize poison timer poisonTimer = timeBetweenDeductions; // reduce agent's speed myBehavior.AgentSpeed *= 0.85f; }
private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); for (int i = 0; i < colliders.Length; i++) { Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); if (!targetRigidbody) { continue; } targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius); AgentHealth agentHealth = targetRigidbody.GetComponent <AgentHealth>(); CapsuleCollider capsuleCollider = targetRigidbody.GetComponent <CapsuleCollider>(); if (agentHealth == null) { continue; } float damage = CalculateDamage(targetRigidbody.position); if (!isShell && capsuleCollider != null) { agentHealth.ColorTarget(targetRigidbody); } else if (isShell && capsuleCollider != null) { agentHealth.TakeDamageTarget(damage, m_TankInstance); } } m_ExplosionParticles.transform.parent = null; m_ExplosionParticles.Play(); m_ExplosionAudio.Play(); Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.duration); Destroy(gameObject); }
public AgentState(GameObject gameObject) : base(gameObject) { self = gameObject.GetComponent <Agent>(); agentStats = self.agentStats; controller = gameObject.GetComponent <AgentController>(); groundLayer = self.groundLayer; charController = gameObject.GetComponent <CharacterController>(); weapons = gameObject.GetComponent <AgentWeapons>(); health = gameObject.GetComponent <AgentHealth>(); stamina = gameObject.GetComponent <AgentStamina>(); vigor = gameObject.GetComponent <AgentVigor>(); anim = gameObject.GetComponentInChildren <Animator>(); audioManager = AudioManager.instance; poolManager = PoolManager.Instance; animEvents = gameObject.GetComponentInChildren <AgentAnimEvents>(); navAgent = gameObject.GetComponent <NavMeshAgent>(); audio = gameObject.GetComponentInChildren <AudioSource>(); transitionsTo.Add(new Transition(typeof(Dying), IsDead)); transitionsTo.Add(new Transition(typeof(TakingDamage), () => health.TookSignificatDamage)); }
private void Start() { healthComponent = observedAgent.RequestComponent <AgentHealth>(); }