public void Flinch(Vector3 dir) { if (!stability) { if ((bool)hurtVoice && ((Status)GetComponent(typeof(Status))).health >= 1) { GetComponent <AudioSource>().clip = hurtVoice; GetComponent <AudioSource>().Play(); } cancelAttack = true; if ((bool)followTarget) { Vector3 position = followTarget.position; Vector3 position2 = transform.position; position.y = position2.y; transform.LookAt(position); } StartCoroutine(KnockBack()); if (!useMecanim) { mainModel.GetComponent <Animation>().PlayQueued(hurtAnimation.name, QueueMode.PlayNow); mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } followState = AIStatef.Moving; } }
void Flinch(Vector3 dir) { if (stability) { return; } if (hurtVoice && GetComponent <StatusC>().health >= 1) { GetComponent <AudioSource>().clip = hurtVoice; GetComponent <AudioSource>().Play(); } cancelAttack = true; if (followTarget) { Vector3 look = followTarget.position; look.y = transform.position.y; transform.LookAt(look); } StartCoroutine(KnockBack()); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().PlayQueued(hurtAnimation.name, QueueMode.PlayNow); mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } followState = AIStatef.Moving; }
public void CheckDistance() { masterDistance = (transform.position - GetMasterPosition()).magnitude; if (masterDistance > 7.0) //////////////////GetMasterPosition { followState = AIStatef.FollowMaster; if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", true); } return; } if (!followTarget) { if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f); } else { animator.SetBool("run", false); } followState = AIStatef.Idle; return; } float distancea = (followTarget.position - transform.position).magnitude; if (distancea <= approachDistance) { Vector3 destinya = followTarget.position; destinya.y = transform.position.y; transform.LookAt(destinya); StartCoroutine(Attack()); } else { followState = AIStatef.Moving; if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", true); } } }
void Start() { gameObject.tag = "Ally"; mainModel = GetComponent <StatusC>().mainModel; if (!mainModel) { mainModel = this.gameObject; } if (!master) { print("Please Assign It's Master first"); } if (!attackPoint) { attackPoint = this.transform; } GetComponent <StatusC>().useMecanim = useMecanim; continueAttack = attackAnimation.Length; atk = GetComponent <StatusC>().atk; mag = GetComponent <StatusC>().matk; followState = AIStatef.FollowMaster; if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().Play(movingAnimation.name); if (hurtAnimation) { mainModel.GetComponent <Animation>()[hurtAnimation.name].layer = 10; GetComponent <StatusC>().hurt = hurtAnimation; } } else { //If using Mecanim Animation if (!animator) { animator = mainModel.GetComponent <Animator>(); } animator.SetBool("run", true); } Physics.IgnoreCollision(GetComponent <Collider>(), master.GetComponent <Collider>()); if (hurtVoice) { GetComponent <StatusC>().hurtVoice = hurtVoice; } }
public void CheckDistance() { masterDistance = (transform.position - GetMasterPosition()).magnitude; if (!(masterDistance <= detectRange + 5f)) { followState = AIStatef.FollowMaster; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", value: true); } return; } if (!followTarget) { if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f); } else { animator.SetBool("run", value: false); } followState = AIStatef.Idle; return; } float magnitude = (followTarget.position - transform.position).magnitude; if (!(magnitude > approachDistance)) { Vector3 position = followTarget.position; Vector3 position2 = transform.position; position.y = position2.y; transform.LookAt(position); StartCoroutine(Attack()); } else { followState = AIStatef.Moving; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", value: true); } } }
//function FindClosest() : GameObject { public GameObject FindClosest() { // Find Closest Player GameObject[] gos; gos = GameObject.FindGameObjectsWithTag("Enemy"); if (gos.Length == 0) { return(null); } GameObject closest = null; float distance = Mathf.Infinity; Vector3 position = transform.position; foreach (GameObject go in gos) { Vector3 diff = (go.transform.position - position); float curDistance = diff.sqrMagnitude; if (curDistance < distance) { //------------ closest = go; distance = curDistance; } } // target = closest; if (!closest) { followTarget = null; followState = AIStatef.FollowMaster; //mainModel.animation.CrossFade(movingAnimation.name, 0.2f); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", true); } return(null); } followTarget = closest.transform; return(closest); }
public GameObject FindClosest() { GameObject[] array = null; array = GameObject.FindGameObjectsWithTag("Enemy"); object result; if (array != null) { GameObject gameObject = null; float num = float.PositiveInfinity; Vector3 position = transform.position; int i = 0; GameObject[] array2 = array; for (int length = array2.Length; i < length; i++) { float sqrMagnitude = (array2[i].transform.position - position).sqrMagnitude; if (!(sqrMagnitude >= num)) { gameObject = array2[i]; num = sqrMagnitude; } } if ((bool)gameObject) { followTarget = gameObject.transform; result = gameObject; goto IL_00ef; } followTarget = null; followState = AIStatef.FollowMaster; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", value: true); } } result = null; goto IL_00ef; IL_00ef: return((GameObject)result); }
public void Start() { gameObject.tag = "Ally"; if (!mainModel) { mainModel = gameObject; } ((Status)GetComponent(typeof(Status))).mainModel = mainModel; if (!master) { MonoBehaviour.print("Please Assign It's Master first"); } if (!attackPoint) { attackPoint = transform; } ((Status)GetComponent(typeof(Status))).useMecanim = useMecanim; continueAttack = attackAnimation.Length; atk = ((Status)GetComponent(typeof(Status))).atk; mag = ((Status)GetComponent(typeof(Status))).matk; followState = AIStatef.FollowMaster; if (!useMecanim) { mainModel.GetComponent <Animation>().Play(movingAnimation.name); if ((bool)hurtAnimation) { mainModel.GetComponent <Animation>()[hurtAnimation.name].layer = 10; } } else { if (!animator) { animator = (Animator)mainModel.GetComponent(typeof(Animator)); } animator.SetBool("run", value: true); } if ((bool)master) { Physics.IgnoreCollision(GetComponent <Collider>(), master.GetComponent <Collider>()); } }
public void Update() { CharacterController characterController = (CharacterController)GetComponent(typeof(CharacterController)); Status status = (Status)GetComponent(typeof(Status)); if (!master) { status.Death(); } else if (meleefwd && !status.freeze) { Vector3 a = transform.TransformDirection(Vector3.forward); characterController.Move(a * 5f * Time.deltaTime); } else { if (freeze || status.freeze) { return; } if (useMecanim) { animator.SetBool("hurt", flinch); } if (flinch) { cancelAttack = true; Vector3 a = transform.TransformDirection(Vector3.back); characterController.SimpleMove(a * 5f); return; } if (!((master.position - transform.position).magnitude <= 30f)) { Vector3 position = master.position; position.y += 1.7f; transform.position = position; } FindClosest(); if (followState == AIStatef.FollowMaster) { if (!((master.position - transform.position).magnitude > 3f)) { followState = AIStatef.Idle; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f); } else { animator.SetBool("run", value: false); } } else { Vector3 a2 = transform.TransformDirection(Vector3.forward); characterController.Move(a2 * speed * Time.deltaTime); Vector3 position2 = master.position; Vector3 position3 = transform.position; position2.y = position3.y; transform.LookAt(position2); } } else if (followState == AIStatef.Moving) { masterDistance = (transform.position - GetMasterPosition()).magnitude; if (!(masterDistance <= detectRange + 5f)) { followState = AIStatef.FollowMaster; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", value: true); } } else if (!((followTarget.position - transform.position).magnitude > approachDistance)) { followState = AIStatef.Pausing; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f); } else { animator.SetBool("run", value: false); } StartCoroutine(Attack()); } else if (!((followTarget.position - transform.position).magnitude < lostSight)) { ((Status)GetComponent(typeof(Status))).health = ((Status)GetComponent(typeof(Status))).maxHealth; followState = AIStatef.Idle; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f); } else { animator.SetBool("run", value: false); } } else { Vector3 a2 = transform.TransformDirection(Vector3.forward); characterController.Move(a2 * speed * Time.deltaTime); Vector3 position4 = followTarget.position; Vector3 position5 = transform.position; position4.y = position5.y; transform.LookAt(position4); } } else if (followState == AIStatef.Pausing) { Vector3 position6 = followTarget.position; Vector3 position7 = transform.position; position6.y = position7.y; transform.LookAt(position6); distance = (transform.position - GetDestination()).magnitude; masterDistance = (transform.position - GetMasterPosition()).magnitude; if (!(masterDistance <= 12f)) { followState = AIStatef.FollowMaster; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", value: true); } } else if (!(distance <= approachDistance)) { followState = AIStatef.Moving; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", value: true); } } } else { if (followState != AIStatef.Idle) { return; } Vector3 position8 = followTarget.position; Vector3 position9 = transform.position; position8.y = position9.y - position8.y; int num = ((Status)GetComponent(typeof(Status))).maxHealth - ((Status)GetComponent(typeof(Status))).health; distance = (transform.position - GetDestination()).magnitude; masterDistance = (transform.position - GetMasterPosition()).magnitude; if (!(distance >= detectRange) && !(Mathf.Abs(position8.y) > 4f) && (bool)followTarget) { followState = AIStatef.Moving; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", value: true); } } else if (!(masterDistance <= 3f)) { followState = AIStatef.FollowMaster; if (!useMecanim) { mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", value: true); } } } } }
void Update() { CharacterController controller = GetComponent <CharacterController>(); StatusC stat = GetComponent <StatusC>(); if (!master) { stat.Death(); return; } if (meleefwd && !stat.freeze) { Vector3 lui = transform.TransformDirection(Vector3.forward); controller.Move(lui * 5 * Time.deltaTime); return; } if (freeze || stat.freeze || GlobalConditionC.freezeAll) { return; } if (useMecanim) { animator.SetBool("hurt", flinch); } if (flinch) { cancelAttack = true; Vector3 lui = transform.TransformDirection(Vector3.back); controller.SimpleMove(lui * 5); return; } if ((master.position - transform.position).magnitude > 30.0f) { Vector3 pos = master.position; pos.y += 1.7f; transform.position = pos; } FindClosest(); if (followState == AIStatef.FollowMaster) { //--------------------------------- if ((master.position - transform.position).magnitude <= 3.0f) { followState = AIStatef.Idle; //mainModel.animation.CrossFade(idleAnimation.name, 0.2ff); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f); } else { animator.SetBool("run", false); } } else { Vector3 forward = transform.TransformDirection(Vector3.forward); controller.Move(forward * speed * Time.deltaTime); Vector3 mas = master.position; mas.y = transform.position.y; transform.LookAt(mas); } //--------------------------------- } else if (followState == AIStatef.Moving) { masterDistance = (transform.position - GetMasterPosition()).magnitude; if (masterDistance > detectRange + 5.0f) //////////////////GetMasterPosition { followState = AIStatef.FollowMaster; //mainModel.animation.CrossFade(movingAnimation.name, 0.2f); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", true); } } else if ((followTarget.position - transform.position).magnitude <= approachDistance) { followState = AIStatef.Pausing; //mainModel.animation.CrossFade(idleAnimation.name, 0.2f); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f); } else { animator.SetBool("run", false); } //----Attack---- //Attack(); StartCoroutine(Attack()); } else if ((followTarget.position - transform.position).magnitude >= lostSight) { //Lost Sight GetComponent <StatusC>().health = GetComponent <StatusC>().maxHealth; followState = AIStatef.Idle; //mainModel.animation.CrossFade(idleAnimation.name, 0.2ff); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f); } else { animator.SetBool("run", false); } } else { Vector3 forward = transform.TransformDirection(Vector3.forward); controller.Move(forward * speed * Time.deltaTime); Vector3 destiny = followTarget.position; destiny.y = transform.position.y; transform.LookAt(destiny); } } else if (followState == AIStatef.Pausing) { Vector3 destinya = followTarget.position; destinya.y = transform.position.y; transform.LookAt(destinya); distance = (transform.position - GetDestination()).magnitude; masterDistance = (transform.position - GetMasterPosition()).magnitude; if (masterDistance > 12.0f) //////////////////GetMasterPosition { followState = AIStatef.FollowMaster; //mainModel.animation.CrossFade(movingAnimation.name, 0.2f); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", true); } } else if (distance > approachDistance) { followState = AIStatef.Moving; //mainModel.animation.CrossFade(movingAnimation.name, 0.2f); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", true); } } } //----------------Idle Mode-------------- else if (followState == AIStatef.Idle) { Vector3 destinyheight = Vector3.zero; if (followTarget) { destinyheight = followTarget.position; destinyheight.y = transform.position.y - destinyheight.y; distance = (transform.position - GetDestination()).magnitude; } masterDistance = (transform.position - GetMasterPosition()).magnitude; if (distance < detectRange && Mathf.Abs(destinyheight.y) <= 4 && followTarget) { followState = AIStatef.Moving; //mainModel.animation.CrossFade(movingAnimation.name, 0.2f); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", true); } } else if (masterDistance > 3.0f) //////////////////GetMasterPosition { followState = AIStatef.FollowMaster; //mainModel.animation.CrossFade(movingAnimation.name, 0.2f); if (!useMecanim) { //If using Legacy Animation mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f); } else { animator.SetBool("run", true); } } } //----------------------------------- }