private void LookForMushroom() { if (!mushroom_in_head) { GameObject[] mushrooms = GameObject.FindGameObjectsWithTag("mushroom"); GameObject closest = null; float closest_dist = 9999999; for (int i = 0; i < mushrooms.Length; ++i) { float dist = Mathf.Abs(Vector3.Distance(gameObject.transform.position, mushrooms[i].transform.position)); if (dist < closest_dist) { closest_dist = dist; closest = mushrooms[i]; } } if (closest != null && Mathf.Abs(Vector3.Distance(gameObject.transform.position, closest.transform.position)) < 1) { mushroom_in_head = true; type_in_head = closest.GetComponent <Mushroom>().GetMushroomType(); alive_in_head.Start(); player_mushroom.SetActive(true); switch (type_in_head) { case Mushroom.MushroomType.MT_PLATFORM: player_mushroom.GetComponent <Animator>().SetBool("platform", true); break; case Mushroom.MushroomType.MT_WIND: player_mushroom.GetComponent <Animator>().SetBool("blow", true); break; case Mushroom.MushroomType.MT_CANON: player_mushroom.GetComponent <Animator>().SetBool("canon", true); break; default: break; } } if (alive && !animator.GetBool("respawn") && !animator.GetBool("death") && !animator.GetBool("peck")) { animator.SetBool("peck", true); peck.Start(); } } }
//Load public int Load(string path) { string[] info = File.ReadAllLines(path); System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US"); int invalidData = 0; for (int i = 1; i < info.Length; i++) { //Split string[] dataInfo = Regex.Split(info[i], ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); //... //... try { //Type Mushroom.MushroomType type = Mushroom.MushroomType.Edible;//0 if (dataInfo[0].Equals("e")) { type = Mushroom.MushroomType.Edible; } else if (dataInfo[0].Equals("p")) { type = Mushroom.MushroomType.Poisonous; } //Info char capShape = Char.Parse(dataInfo[1]); //1 char capSurface = Char.Parse(dataInfo[2]); //2 char capColor = Char.Parse(dataInfo[3]); //3 char bruises = Char.Parse(dataInfo[4]); //4 char odor = Char.Parse(dataInfo[5]); //5 char gillAttachment = Char.Parse(dataInfo[6]); //6 char gillSpacing = Char.Parse(dataInfo[7]); //7 char gillSize = Char.Parse(dataInfo[8]); //8 char gillColor = Char.Parse(dataInfo[9]); //9 char stalkShape = Char.Parse(dataInfo[10]); //10 char stalkRoot = Char.Parse(dataInfo[11]); //11 char stalkSurfaceAboveRing = Char.Parse(dataInfo[12]); //12 char stalkSurfaceBelowRing = Char.Parse(dataInfo[13]); //13 char stalkColorAboveRing = Char.Parse(dataInfo[14]); //14 char stalkColorBelowRing = Char.Parse(dataInfo[15]); //15 char veilType = Char.Parse(dataInfo[16]); //16 char veilColor = Char.Parse(dataInfo[17]); //17 char ringNumber = Char.Parse(dataInfo[18]); //18 char ringType = Char.Parse(dataInfo[19]); //19 char sporePrintColor = Char.Parse(dataInfo[20]); //20 char population = Char.Parse(dataInfo[21]); //21 char habitad = Char.Parse(dataInfo[22]); //22 //Add Mushroom mushroom = new Mushroom(type, capShape, capSurface, capColor, bruises, odor, gillAttachment, gillSpacing, gillSize, gillColor, stalkShape, stalkRoot, stalkSurfaceAboveRing, stalkSurfaceBelowRing, stalkColorAboveRing, stalkColorBelowRing, veilType, veilColor, ringNumber, ringType, sporePrintColor, population, habitad); dataSet.Add(mushroom); } catch (IndexOutOfRangeException) { invalidData++; } catch (InvalidValuesException) { invalidData++; } //... } return(invalidData); }