Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EnemyAI : MonoBehaviour
- {
- public int enemyhealth;
- public int energy;
- public float distance;
- public float waitforaction;
- public int act;
- public int attackact;
- public int range;
- public GameObject player;
- public int playerevade;
- public int accuracy;
- public int accuracyhalf;
- //attacks
- public int attackoneaccuracy;
- //chance to hit
- public int attackcost;
- //energy lost
- public int attackonedamage;
- //damage to player
- public int attackoneenergy;
- //if enemy energy is gained
- public int attackonechangehealth;
- //if enemy health is gained
- public int changeactone;
- //if enemy attack time is changed
- public int attacktwoaccuracy;
- public int attackcosttwo;
- public int attacktwodamage;
- public int attacktwoenergy;
- public int attacktwochangehealth;
- public int changeacttwo;
- public int attackthreeaccuracy;
- public int attackcostthree;
- public int attackthreedamage;
- public int attackthreeenergy;
- public int attackthreechangehealth;
- public int changeacthree;
- void Start ()
- {
- player = GameObject.Find("Pigobj");
- StartCoroutine("action");
- }
- IEnumerator action ()
- {
- act = Random.Range (0, 10);
- if (act == 1 && energy > 0)
- {
- act = 0;
- StartCoroutine("right");
- }
- if (act == 2 && energy > 0)
- {
- act = 0;
- StartCoroutine("left");
- }
- if (act == 3 && energy > 0)
- {
- act = 0;
- StartCoroutine("up");
- }
- if (act == 4 && energy > 0)
- {
- act = 0;
- StartCoroutine("down");
- }
- if (act >= 5 && energy > 0)
- {
- act = 0;
- StartCoroutine("attack");
- }
- yield return new WaitForSeconds(waitforaction);
- StartCoroutine("action");
- }
- IEnumerator right ()
- {
- energy -= 1;
- this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (distance, 0.0f, 0.0f);
- yield return new WaitForSeconds(2);
- }
- IEnumerator left ()
- {
- energy -= 1;
- this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (-distance, 0.0f, 0.0f);
- yield return new WaitForSeconds(2);
- }
- IEnumerator up ()
- {
- energy -= 1;
- this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (0.0f, 0.0f, distance);
- yield return new WaitForSeconds(2);
- }
- IEnumerator down ()
- {
- energy -= 1;
- this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (0.0f, 0.0f, -distance);
- yield return new WaitForSeconds(2);
- }
- IEnumerator attack ()
- {
- if (Vector3.Distance (player.transform.position, this.gameObject.transform.position) < range)
- {
- attackact = Random.Range (0, 3);
- if (attackact == 1)
- {
- StartCoroutine("attackone");
- }
- if (attackact == 2)
- {
- StartCoroutine("attacktwo");
- }
- if (attackact == 3)
- {
- StartCoroutine("attackthree");
- }
- }
- yield return new WaitForSeconds(2);
- }
- //add evade option
- IEnumerator attackone ()
- {
- energy -= attackcost;
- playerevade = GameObject.Find ("Pigobj").GetComponent<Master>().evade;
- accuracyhalf = playerevade / 2;
- accuracy = Random.Range (playerevade, attackoneaccuracy);
- if (playerevade < accuracyhalf)
- {
- GameObject.Find("Pigobj").GetComponent<Master>().currenthealth -= attackonedamage;
- enemyhealth += attackonechangehealth;
- energy += attackoneenergy;
- waitforaction = changeactone;
- yield return new WaitForSeconds(2);
- }
- }
- IEnumerator attacktwo ()
- {
- energy -= attackcosttwo;
- playerevade = GameObject.Find ("Pigobj").GetComponent<Master>().evade;
- accuracyhalf = playerevade / 2;
- accuracy = Random.Range (playerevade, attacktwoaccuracy);
- if (accuracy < accuracyhalf)
- {
- GameObject.Find("Pigobj").GetComponent<Master>().currenthealth -= attacktwodamage;
- enemyhealth += attacktwochangehealth;
- energy += attacktwoenergy;
- waitforaction = changeacttwo;
- yield return new WaitForSeconds(2);
- }
- }
- IEnumerator attackthree ()
- {
- energy -= attackcostthree;
- playerevade = GameObject.Find ("Pigobj").GetComponent<Master>().evade;
- accuracyhalf = playerevade / 2;
- accuracy = Random.Range (playerevade, attackthreeaccuracy);
- if (accuracy < accuracyhalf)
- {
- GameObject.Find("Pigobj").GetComponent<Master>().currenthealth -= attackthreedamage;
- enemyhealth += attackthreechangehealth;
- energy += attackthreeenergy;
- waitforaction = changeacthree;
- yield return new WaitForSeconds(2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement