void DoAttackControls() { if (!isAttacking) { attackObject.transform.localPosition = Vector3.zero + Vector3.up * 0.375f; attackObject.transform.localScale = new Vector3(1, 0.5f, 1); if (!Input.GetKey("joystick button 4") && !Input.GetKey("joystick button 5")) //if (!Input.GetKey(KeyCode.Alpha1) && !Input.GetKey(KeyCode.Alpha2) && !Input.GetKey(KeyCode.LeftShift)) { if (/*Input.GetMouseButtonDown(0)*/ Input.GetAxis("Fire1") > 0) { attackObjRenderer.material.color = new Color(0.75f, 0, 0, 0.5f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.Melee, 0, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.Melee; attackObjectControl.attackElement = Attacks.AtkDefElement.Rock; isAttacking = true; } if (/*Input.GetMouseButtonDown(1)*/ Input.GetAxis("Fire2") > 0) { attackObjRenderer.material.color = new Color(0, 0, 0.75f, 0.5f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.Melee, 1, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.Melee; attackObjectControl.attackElement = Attacks.AtkDefElement.Paper; isAttacking = true; } if (/*Input.GetMouseButtonDown(2)*/ Input.GetAxis("Fire3") > 0) { attackObjRenderer.material.color = new Color(0.75f, 0.75f, 0, 0.5f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.Melee, 2, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.Melee; attackObjectControl.attackElement = Attacks.AtkDefElement.Scissors; isAttacking = true; } } else if (!Input.GetKey("joystick button 4") && Input.GetKey("joystick button 5")) { if (Input.GetAxis("Fire1") > 0) { attackObjRenderer.material.color = new Color(0.75f, 0, 0, 1f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.Ranged, 0, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.Ranged; attackObjectControl.attackElement = Attacks.AtkDefElement.Rock; isAttacking = true; } if (Input.GetAxis("Fire2") > 0) { attackObjRenderer.material.color = new Color(0, 0, 0.75f, 1f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.Ranged, 1, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.Ranged; attackObjectControl.attackElement = Attacks.AtkDefElement.Paper; isAttacking = true; } if (Input.GetAxis("Fire3") > 0) { attackObjRenderer.material.color = new Color(0.75f, 0.75f, 0, 1f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.Ranged, 2, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.Ranged; attackObjectControl.attackElement = Attacks.AtkDefElement.Scissors; isAttacking = true; } } else if (Input.GetKey("joystick button 4") && !Input.GetKey("joystick button 5")) { if (Input.GetAxis("Fire1") > 0) //Defense Mechanism { attackElement = Attacks.AtkDefElement.Rock; defenseMatRenderer.material.SetColor("_RimColor", Color.red); var main = defenseParts.main; main.startColor = Color.red; // miningLight.color = new Color(255f / 255f, 0 / 255f, 15f / 255f); } if (Input.GetAxis("Fire2") > 0) { attackElement = Attacks.AtkDefElement.Paper; defenseMatRenderer.material.SetColor("_RimColor", Color.blue); var main = defenseParts.main; main.startColor = Color.blue; // miningLight.color = new Color(0 / 255f, 94f / 255f, 255f / 255f); } if (Input.GetAxis("Fire3") > 0) { attackElement = Attacks.AtkDefElement.Scissors; defenseMatRenderer.material.SetColor("_RimColor", Color.yellow); var main = defenseParts.main; main.startColor = Color.yellow; // miningLight.color = new Color(255f / 255f, 205f / 255f, 0 / 255f); } } else if (Input.GetKey("joystick button 4") && Input.GetKey("joystick button 5")) { if (Input.GetAxis("Fire1") > 0) { attackObjRenderer.material.color = new Color(0.75f, 0, 0, 0.75f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.AoE, 0, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.AoE; attackObjectControl.attackElement = Attacks.AtkDefElement.Rock; isAttacking = true; } if (Input.GetAxis("Fire2") > 0) { attackObjRenderer.material.color = new Color(0, 0, 0.75f, 0.75f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.AoE, 1, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.AoE; attackObjectControl.attackElement = Attacks.AtkDefElement.Paper; isAttacking = true; } if (Input.GetAxis("Fire3") > 0) { attackObjRenderer.material.color = new Color(0.75f, 0.75f, 0, 0.75f); StartCoroutine(Attacks.PerformAttack(Attacks.AttackType.AoE, 2, attackObject, this.gameObject, attacksCooldown, this)); attackObjectControl.attackType = Attacks.AttackType.AoE; attackObjectControl.attackElement = Attacks.AtkDefElement.Scissors; isAttacking = true; } } } if (isAttacking) { attackTimer += Time.deltaTime; } if (!attackObject.activeSelf) //attackTimer>attacksCooldown) { attackTimer = 0; isAttacking = false; } }
// Update is called once per frame void Update() { // if (Input.GetKey(KeyCode.Space)) // isLunging = true; // else isLunging = false; CheckTerrainPosition(); if (isGrounded) { if (!isWandering) { transform.LookAt(target); } else { transform.LookAt(randomDir); } if (!isLunging) { lungeTimer += Time.deltaTime; if (lungeTimer > timeToLunge) { isLunging = true; lungeTimer = 0; } } } if (isLunging) { lungingTimer += Time.deltaTime; if (lungingTimer > lungingTime) { lungingTimer = 0; isLunging = false; } } if (Vector3.SqrMagnitude(target.position - transform.position) > Mathf.Pow(sightRange * 2, 2)) { isWandering = true; } else { isWandering = false; } if (Vector3.SqrMagnitude(target.position - transform.position) < Mathf.Pow(playerDist, 2) && !isWandering) { inAttackRange = true; } else { inAttackRange = false; } if (isWandering) { wanderTimer += Time.deltaTime; if (wanderTimer > timeToWander) { wanderTimer = 0; randomDir = Random.onUnitSphere.normalized; } } if (inAttackRange) { CheckTextureMap(); attackTimer += Time.deltaTime; if (attackTimer > attackTime * 2 && !attackObject.activeSelf) { attackTimer = 0; if (Random.Range(0, attackTimerRandomMult) == 0) { this.RefreshAttackTimers(); } attackTime = Random.Range(attackTimeMin, attackTimeMax); StartCoroutine(Attacks.PerformAttack(attackType, 0, attackObject, this.gameObject, attackTime)); attackObjectControl.attackType = attackType; attackObjectControl.attackElement = attackElement; attackObjectControl.source = this.transform; attackObjRenderer.material.color = new Color(0.75f, 0.75f, 0, 0.75f); } } ClipHeight(); }