private void OnTriggerEnter(Collider other) { AttackableGameObject target = other.GetComponent <AttackableGameObject>(); if (target != null && !other.gameObject.Equals(originTarget)) { Attack attack = new Attack("ability", null, other.gameObject, damage); attackManager.QueueAttack(attack); Destroy(gameObject); } }
// Update is called once per frame void Update() { if (!gameOver) { int count = 4; foreach (GameObject enemy in enemies) { AttackableGameObject temp = enemy.GetComponentInChildren <AttackableGameObject>(); if (temp != null && !temp.IsDead()) { count--; } } if (count == 4) { gameOver = true; Invoke("Win", 3); } } if (!gameOver) { int count = 2; foreach (GameObject player in players) { AttackableGameObject temp = player.GetComponent <AttackableGameObject>(); if (temp != null && !temp.IsDead()) { count--; } } if (count == 2) { gameOver = true; Invoke("Lose", 3); } } }
// Update is called once per frame void Update() { if (cutsceneManager.CutsceneHappening()) { if (agent.remainingDistance < 0.5) { animator.SetBool("IsMoving", false); } else { animator.SetBool("IsMoving", true); } } else { if (pauseManager.IsPaused()) { // If we are now paused, and this isn't paused yet if (!lastPauseStatus) { lastPauseStatus = true; pauseVelocity = agent.velocity; agent.velocity = Vector3.zero; agent.isStopped = true; animator.enabled = false; } } else { // If we aren't paused, but this still is if (lastPauseStatus) { lastPauseStatus = false; agent.velocity = pauseVelocity; agent.isStopped = false; animator.enabled = true; } if (status != null && !IsDead()) { agent.velocity = Vector3.zero; agent.isStopped = true; animator.enabled = false; if (status.type == "push") { Vector3 originToTarget = status.origin - transform.position; Vector3 direction = new Vector3( Vector3.Normalize(originToTarget).x, 0, Vector3.Normalize(originToTarget).z); transform.parent.Translate(direction * Time.deltaTime * 15); if (originToTarget.magnitude >= 10) { status = null; animator.enabled = true; agent.isStopped = false; } } if (timeManager.getTimeSeconds() - statusStartTime > status.length) { RemoveStatus(); } } else { if (currentTarget != null) { AttackableGameObject target = currentTarget.GetComponent <AttackableGameObject>(); if (target == null || target.IsDead()) { players.Remove(currentTarget); ChooseTarget(); } else { Vector3 playerPosition = currentTarget.transform.position; float distance = (transform.position - playerPosition).magnitude; NavMeshPath path = new NavMeshPath(); agent.CalculatePath(playerPosition, path); if (distance > RANGED_DISTANCE || path.corners.Length > 2) { agent.destination = playerPosition; animator.SetBool("IsMoving", true); ChooseTarget(); } else { agent.velocity = Vector3.zero; agent.destination = transform.position; if (timeManager.getTimeSeconds() - lastAttackTime > RANGED_ATTACK_CD) { transform.LookAt(new Vector3(currentTarget.transform.position.x, transform.position.y, currentTarget.transform.position.z)); transform.Rotate(0, -135, 0); Attack attack = new Attack("autoattack", gameObject, currentTarget, 10); GameObject autoAttack = Instantiate(autoAttackPrefab, transform.position + transform.forward, transform.rotation); autoAttack.GetComponent <RangedAutoAttackProjectile>().setAttack(attack); lastAttackTime = timeManager.getTimeSeconds(); animator.SetBool("IsMoving", false); animator.SetTrigger("IsAttacking"); } } } } else { ChooseTarget(); if (currentTarget == null) { animator.SetBool("IsMoving", false); } } } } } }
// Update is called once per frame void Update() { if (cutsceneManager.CutsceneHappening()) { if (currentTarget != null) { AttackTarget(); } if (agent.remainingDistance < 0.5) { animator.SetBool("IsMoving", false); } else { animator.SetBool("IsMoving", true); } } else { if (pauseManager.IsPaused()) { // If we are now paused, and this isn't paused yet if (!lastPauseStatus) { lastPauseStatus = true; pauseVelocity = agent.velocity; agent.velocity = Vector3.zero; agent.isStopped = true; animator.enabled = false; } } else { // If we aren't paused, but this still is if (lastPauseStatus) { lastPauseStatus = false; agent.velocity = pauseVelocity; agent.isStopped = false; animator.enabled = true; } if (status != null && !IsDead()) { agent.velocity = Vector3.zero; agent.isStopped = true; animator.enabled = false; if (status.type == "push") { Vector3 originToTarget = status.origin - transform.position; Vector3 direction = new Vector3( Vector3.Normalize(originToTarget).x, 0, Vector3.Normalize(originToTarget).z); transform.parent.Translate(direction * Time.deltaTime * 15); if (originToTarget.magnitude >= 10) { status = null; animator.enabled = true; agent.isStopped = false; } } if (timeManager.getTimeSeconds() - statusStartTime > status.length) { RemoveStatus(); } } else { if (currentTarget != null) { AttackableGameObject target = currentTarget.GetComponent <AttackableGameObject>(); if (target == null || target.IsDead()) { players.Remove(currentTarget); ChooseTarget(); } else { AttackTarget(); } } else { ChooseTarget(); if (currentTarget == null) { animator.SetBool("IsMoving", false); } } } } } }
public void Unsubscribe(AttackableGameObject owner) { UnityAction <Attack> callback = owner.OnAttacked; attackEvent.RemoveListener(callback); }