/// <summary> /// Depending on the phase the demo is in, have the agent do the appropriate steering. /// /// </summary> void FixedUpdate() { switch (phase) { case 0: if (label) { label.text = tag; } break; case 1: if (label) { label.text = "Wander"; } (linear, angular) = Algo("Wander"); break; case 2: if (label) { label.text = "Evade"; } (linear, angular) = Algo("Evade"); //wolf if (ai.DistanceToTarget() < 2f) { linear = new Vector3(0f, 0f, 0f); ai.Stop(); label.text = "Collision!"; // Destroy(self); Invoke("DisappearWolf", 3); Invoke("DisappearHunter", 3); return; } break; case 3: if (label) { label.text = "Pursue"; } (linear, angular) = Algo("Pursue"); //if (ai.target.tag == "Red(Clone)" && ai.DistanceToTarget() < 2f) //{ // //phase = 5; //} if (ai.tag == "Wolf") { if (ai.DistanceToTarget() < 1.5f) { //linear = new Vector3(0, 0, 0); //angular = 0; if (timeCounter > 50) //1second { ai.Stop(); timeCounter -= 1; } else if (timeCounter <= 0) { (linear, angular) = Algo("Pursue"); timeCounter = 150; } else { ai.target = ai.house; //phase = 7;//gotohouse timeCounter -= 1; //timeCounter = 150; } } } //must be wolf, already meet red, target now is house if (ai.target.tag != "Red" && ai.DistanceToTarget() < 5f) { //Debug.Log(ai.tag+"?????????????????????????/"); phase = 5; } break; case 4: if (label) { label.text = "Wander"; } (linear, angular) = Algo("Wander"); if (ai.DistanceToTarget() < 20f) { if (ai.tag == "Wolf") { phase = 2; } else { phase = 3; } } break; case 5: if (label) { label.text = "Arrive"; } linear = ai.Arrive(); angular = ai.Face(); Debug.Log(ai.tag + " " + ai.distanceToHouse()); if (ai.ArriveHouse()) { phase = 9; } break; case 6: if (label) { label.text = "PathFollowWithAvoid"; } (linear, angular) = Algo("PathFollow"); if (GameObject.FindGameObjectsWithTag("Wolf").Length >= 1 && (ai.agent.position - GameObject.FindGameObjectsWithTag("Wolf")[0].GetComponent <NPCController>().position).magnitude < 1.5f) { if (timeCounter > 50) //1second { ai.Stop(); timeCounter -= 1; } else if (timeCounter <= 0) { (linear, angular) = Algo("PathFollow"); timeCounter = 150; } else { (linear, angular) = Algo("PathFollow"); timeCounter -= 1; } } break; case 7: if (label) { label.text = "gotohouse"; } linear = ai.Arrive(ai.target.position - ai.agent.position); angular = ai.Face(); Debug.Log(ai.tag + " " + ai.distanceToHouse()); if (ai.ArriveHouse()) { phase = 9; } break; case 8: if (label) { label.text = "SeekWithArrive"; } (linear, angular) = Algo("SeekWithArrive"); break; case 9: if (label) { label.text = ""; } if (ai.tag == "Wolf") { DisappearWolf(); GameObject.FindGameObjectWithTag("Narrator").GetComponent <Text>().text += "Wolf arrives!\n"; } else if (ai.tag == "Hunter") { DisappearHunter(); GameObject.FindGameObjectWithTag("Narrator").GetComponent <Text>().text += "Hunter arrives!\n"; } else { DisappearRed(); GameObject.FindGameObjectWithTag("Narrator").GetComponent <Text>().text += "Red arrives!\n"; } addEndingStory(); break; } update(linear, angular, Time.deltaTime); if (label) { label.transform.position = Camera.main.WorldToScreenPoint(this.transform.position); } }