// Use this for initialization void Start() { ap = GetComponent <AnimalPart>(); }
public void fusion(Vector3 pos) { if (AllreadyInstance > 29) { return; } Instantiate(GameObject.FindObjectOfType <TerrainGenerator>().animCoeur, pos, Quaternion.identity); GameObject.FindGameObjectWithTag("soundmanager").GetComponent <soundManagerScript>().kiss.Play(); GameObject e = new GameObject("newAnimal"); e.transform.position = Vector3.zero; Animal X = e.AddComponent <Animal>(); //X.state = "Fly"; e.SetActive(false); SphereCollider TP = e.AddComponent <SphereCollider>(); TP.radius = 0.5f; TP.isTrigger = true; e.AddComponent <Rigidbody>().isKinematic = true; e.AddComponent <UnityEngine.AI.NavMeshAgent>(); List <string> descriptionPart = new List <string>(); // body choice; GameObject newBody = null; Transform initialBody = null; if (Random.value > 0.5) { newBody = Instantiate(animal1.FindChild("Body").gameObject, Vector3.zero, Quaternion.identity) as GameObject; initialBody = animal1.FindChild("Body"); } else { newBody = Instantiate(animal2.FindChild("Body").gameObject, Vector3.zero, Quaternion.identity) as GameObject; initialBody = animal2.FindChild("Body"); } newBody.transform.parent = e.transform; newBody.transform.localPosition = Vector3.zero; newBody.transform.localRotation = initialBody.localRotation; List <GameObject> children = new List <GameObject>(); foreach (Transform child in newBody.transform) { children.Add(child.gameObject); } children.ForEach(child => Destroy(child)); newBody.name = "Body"; if (newBody.GetComponent <AnimalPart>()) { descriptionPart.Add(newBody.GetComponent <AnimalPart>().description); } // head part : Transform head = null; if (Random.value > 0.5) { head = Instantiate(animal1.FindChild("Body").FindChild("Head")) as Transform; } else { head = Instantiate(animal2.FindChild("Body").FindChild("Head")) as Transform; } head.name = "Head"; head.parent = newBody.transform; head.localPosition = initialBody.FindChild("Head").localPosition; head.localRotation = initialBody.FindChild("Head").localRotation; if (head.GetComponent <AnimalPart>()) { descriptionPart.Add(head.GetComponent <AnimalPart>().description); } // front Transform frontA = null; Transform frontB = null; if (Random.value > 0.5) { frontA = Instantiate(animal1.FindChild("Body").FindChild("FrontR")) as Transform; frontB = Instantiate(animal1.FindChild("Body").FindChild("FrontL")) as Transform; } else { frontA = Instantiate(animal2.FindChild("Body").FindChild("FrontR")) as Transform; frontB = Instantiate(animal2.FindChild("Body").FindChild("FrontL")) as Transform; } frontA.parent = newBody.transform; frontA.localPosition = initialBody.FindChild("FrontR").localPosition; frontA.localRotation = initialBody.FindChild("FrontR").localRotation; frontB.parent = newBody.transform; frontB.localPosition = initialBody.FindChild("FrontL").localPosition; frontB.localRotation = initialBody.FindChild("FrontL").localRotation; frontA.name = "FrontR"; frontB.name = "FrontL"; if (frontA.GetComponent <AnimalPart>()) { descriptionPart.Add(frontA.GetComponent <AnimalPart>().description); } // back Transform backA = null; Transform backB = null; if (Random.value > 0.5) { backA = Instantiate(animal1.FindChild("Body").FindChild("BackR")) as Transform; backB = Instantiate(animal1.FindChild("Body").FindChild("BackL")) as Transform; } else { backA = Instantiate(animal2.FindChild("Body").FindChild("BackR")) as Transform; backB = Instantiate(animal2.FindChild("Body").FindChild("BackL")) as Transform; } backA.parent = newBody.transform; backA.localPosition = initialBody.FindChild("BackR").localPosition; backA.localRotation = initialBody.FindChild("BackR").localRotation; backB.parent = newBody.transform; backB.localPosition = initialBody.FindChild("BackL").localPosition; backB.localRotation = initialBody.FindChild("BackL").localRotation; backA.name = "BackR"; backB.name = "BackL"; if (backA.GetComponent <AnimalPart>()) { descriptionPart.Add(backA.GetComponent <AnimalPart>().description); } Egg oeuf = (Instantiate(Resources.Load("spawningEggs"), this.transform.position, Quaternion.identity) as GameObject).GetComponent <Egg>(); oeuf.other = e; e.tag = "Animal"; pos.y = 0f; e.transform.position = pos; e.SetActive(false); string legendaire = AnimalPart.compareTo(descriptionPart); if (legendaire == "Licorne") { GameObject P = Instantiate(FindObjectOfType <TerrainGenerator>().licorne, pos, Quaternion.identity) as GameObject; oeuf.other = P; Destroy(e); } else if (legendaire == "Dragon") { GameObject P = Instantiate(FindObjectOfType <TerrainGenerator>().Dragon, pos, Quaternion.identity) as GameObject; oeuf.other = P; Destroy(e); } }