private IEnumerator Skill2PredictionFire() { StartCoroutine(Dodge(5, dodgeTime / 3)); skillTimer = Time.time + 9999f; canDodge = false; yield return(new WaitForSeconds(0.5f)); Transform[] circlesToFireAt = new Transform[amnOfCircles]; Vector2 posToSpawn; for (int i = 0; i < amnOfCircles; i++) { posToSpawn = target.position + (new Vector3(target.GetComponent <Rigidbody2D>().velocity.x, target.GetComponent <Rigidbody2D>().velocity.y, 0f) * Time.deltaTime) * i * 2.7f; circlesToFireAt[i] = Instantiate(circlePref, posToSpawn, Quaternion.identity) as Transform; targetToFireAt = circlesToFireAt[i]; StartCoroutine(Fire(0f, arrowSkillDmg, arrowSpeed * 1.1f)); Destroy(circlesToFireAt[i].gameObject, 0.25f); yield return(new WaitForSeconds(0.1f)); // circlesToFireAt[i].parent = objectContainer; } targetToFireAt = target; skillTimer = Time.time + skillDelay; curState = AttackingStates.LOCKED_ON; canDodge = true; CheckForPlayer(); }
private IEnumerator Skill1RapidFire() { StartCoroutine(Dodge(5, dodgeTime / 2)); skillTimer = Time.time + 9999f; canDodge = false; yield return(new WaitForSeconds(0.5f)); Transform[] circlesToFireAt = new Transform[amnOfCircles]; Vector2 posToSpawn; for (int i = 0; i < amnOfCircles; i++) { posToSpawn = new Vector2(target.position.x + Random.Range(-6.5f, 6.5f), target.position.y + Random.Range(-2.5f, 2.5f)); circlesToFireAt[i] = Instantiate(circlePref, posToSpawn, Quaternion.identity) as Transform; targetToFireAt = circlesToFireAt[i]; StartCoroutine(Fire(0f, arrowSkillDmg, arrowSpeed * 0.8f)); Destroy(circlesToFireAt[i].gameObject, 0.25f); yield return(new WaitForSeconds(0.08f)); // circlesToFireAt[i].parent = objectContainer; } targetToFireAt = target; skillTimer = Time.time + skillDelay; curState = AttackingStates.LOCKED_ON; canDodge = true; CheckForPlayer(); }
private IEnumerator Skill3CenterRandomFire() { skillTimer = Time.time + 9999f; canDodge = false; yield return(new WaitForSeconds(0.5f)); float x; float y; Transform[] circlesToFireAt = new Transform[amnOfCircles * 3]; Vector2 posToSpawn; for (int i = 0; i < amnOfCircles * 3; i++) { x = Random.Range(-10f, 10f); y = Random.Range(-10f, 10f); if (x < 0) { Mathf.Clamp(x, -5f, -3f); } else { Mathf.Clamp(x, 3f, 5f); } if (y < 0) { Mathf.Clamp(y, -5f, -3f); } else { Mathf.Clamp(y, 3f, 5f); } posToSpawn = new Vector2(transform.position.x + x, transform.position.y + y); circlesToFireAt[i] = Instantiate(circlePref, posToSpawn, Quaternion.identity) as Transform; targetToFireAt = circlesToFireAt[i]; StartCoroutine(Fire(0f, arrowSkillDmg, arrowSpeed * 0.9f)); Destroy(circlesToFireAt[i].gameObject, 0.25f); yield return(new WaitForSeconds(0.14f)); // circlesToFireAt[i].parent = objectContainer; } targetToFireAt = target; skillTimer = Time.time + skillDelay; curState = AttackingStates.LOCKED_ON; canDodge = true; CheckForPlayer(); }
private void CharacterAttack(GameObject character, GameObject target) { Vector3 moveDirection = Vector3.zero; switch (attackState) { case AttackingStates.GOING: character.GetComponent <Animator> ().SetBool("Running", true); moveDirection = new Vector3(0, 0, movementSpeed); character.transform.Translate(moveDirection * Time.deltaTime); if (Mathf.FloorToInt(character.transform.position.z) == 0) { attackState = AttackingStates.ATTACKING; } break; case AttackingStates.ATTACKING: if (attackTimer <= -10.0f) { character.GetComponent <Animator> ().SetBool("Attacking", true); attackTimer = 1.05f; target.GetComponent <Animator> ().SetBool("Damaged", true); } else if (attackTimer <= 0.0f) { character.transform.localRotation *= Quaternion.Euler(0, 180, 0); attackState = AttackingStates.RETURNING; attackTimer = -10.0f; } attackTimer -= Time.deltaTime; break; case AttackingStates.RETURNING: character.GetComponent <Animator> ().SetBool("Running", true); moveDirection = new Vector3(0, 0, movementSpeed); character.transform.Translate(moveDirection * Time.deltaTime); if (Mathf.Abs(character.transform.position.z) >= 10) { character.GetComponent <Animator> ().SetBool("Running", false); character.transform.localRotation *= Quaternion.Euler(0, 180, 0); attackState = AttackingStates.GOING; isActionFinished = true; } break; } }
// Start is called before the first frame update void Start() { if (!rb) { rb = GetComponent <Rigidbody2D>(); } if (!thisEn) { thisEn = GetComponent <Enemy>(); } if (!anim) { anim = GetComponent <Animator>(); } if (!gm) { gm = FindObjectOfType <GameMaster>(); } arrowPool = arrowPref.GetComponent <Poolable>(); curState = AttackingStates.IDLE; }
// Update is called once per frame private void Update() { if (!target) { curState = AttackingStates.IDLE; } if (Time.time > timeLeftToCheck && ((curState != AttackingStates.SKILL_1) || (curState != AttackingStates.SKILL_2))) { CheckForPlayer(); timeLeftToCheck = Time.time + playerCheckDelay; if (target && curState == AttackingStates.IDLE) { if (thisEn.enStats.Health < thisEn.enStats.RetMaxHP() / 3) { curState = AttackingStates.BOW_ATTACK; } else { curState = AttackingStates.SWORD_ATTACK; } } } if (curState == AttackingStates.LOCKED_ON) { if (Time.time > orbitLockonDurationTimer) { if (thisEn.enStats.Health < thisEn.enStats.RetMaxHP() / 3) { curState = AttackingStates.BOW_ATTACK; } else { curState = AttackingStates.SWORD_ATTACK; } orbitLockonDelayTimer = Time.time + orbitLockOnDelay; } } if (target) { if (Vector2.Distance(target.position, transform.position) <= orbitDistance) { if ((curState == AttackingStates.SWORD_ATTACK || curState == AttackingStates.BOW_ATTACK) && Time.time > orbitLockonDelayTimer) { int rng = Random.Range(0, 2); if (rng == 0) { dir = 1; } else { dir = -1; } curState = AttackingStates.LOCKED_ON; orbitLockonDurationTimer = Time.time + orbitLockOnDuration; } } if (curState == AttackingStates.SWORD_ATTACK) { if (Time.time > attackTimer) { if (Vector2.Distance(target.position, transform.position) <= targetMinRange / 2 && anim.GetInteger("swingingNow") == 0) { i = Random.Range(1, amnOfAnims); attackTimer = attackDelay + Time.time; anim.SetInteger("swingingNow", i); } } } else if (curState == AttackingStates.LOCKED_ON || curState == AttackingStates.BOW_ATTACK) { if (Time.time > attackTimer && anim.GetInteger("swingingNow") == 0) { StartCoroutine(Fire(0.4f, arrowDmg, arrowSpeed)); } if (Time.time > skillTimer && amnOfCircles > 0) { int rng = Random.Range(0, amnOfSkills); if (rng == 0) { StartCoroutine(Skill1RapidFire()); curState = AttackingStates.SKILL_1; } else if (rng == 1) { StartCoroutine(Skill2PredictionFire()); curState = AttackingStates.SKILL_2; } else if (rng == 2) { StartCoroutine(Skill3CenterRandomFire()); curState = AttackingStates.SKILL_3; } } } } }