public void InitiateGenerateTank() { TankyBody basePart = collectedParts.collectedBody[bodyDropdown.value]; TankyMobility mobilityPart = collectedParts.collectedMobility[mobilityDropdown.value]; TankyParts[] attachParts = new TankyParts[NumberOfConnectors]; for (int i = 0; i < NumberOfConnectors; i++) { partInDropdown = partsHolder[i].GetComponentInChildren <TMP_Dropdown>().value; //Debug.Log("Part in Dropdown:" + partInDropdown); if (partInDropdown == 0) { //Debug.Log("It was 0"); attachParts[i] = null; } else { if (partInDropdown <= collectedParts.collectedWeapon.Length) { //Debug.Log("WeaponLookup:" + (partInDropdown - 1)); attachParts[i] = collectedParts.collectedWeapon[partInDropdown - 1]; } else { //Debug.Log("MiscLookup:" + (partInDropdown -1 - collectedParts.collectedWeapon.Length)); attachParts[i] = collectedParts.collectedMisc[partInDropdown - 1 - collectedParts.collectedWeapon.Length]; } } } numberOfTanks++; tankSpawn.CreateTank(Vector3.zero + new Vector3((-3 * numberOfTanks), 0, 0), basePart, mobilityPart, attachParts); }
void GeneratePart(TankyParts partToSpawn, Transform Parent, Vector3 offsetDistance, Vector3 offsetAngle) { //New empty GameObject newPart = new GameObject(partToSpawn.partName); ReParent(newPart.transform, Parent); //Offset self newPart.transform.localPosition = offsetDistance; newPart.transform.localRotation = Quaternion.Euler(offsetAngle); //Set up the health system for the part partHealth = newPart.AddComponent <TankyHealth>(); partHealth.maxHealth = partToSpawn.partIndividualHealth; partHealth.ownPart = partToSpawn; //Create the model as a child newMeshChild = new GameObject(partToSpawn.partName + "Mesh"); ReParent(newMeshChild.transform, newPart.transform); newMeshChild.AddComponent <MeshFilter>().mesh = partToSpawn.partMesh; newMeshChild.AddComponent <MeshRenderer>().material = partToSpawn.partTexture; newMeshChild.AddComponent <BoxCollider>(); newMeshChild.AddComponent <Rigidbody>().isKinematic = true; //Add model at offset switch (partToSpawn.partType) { case (partTypes.Weapon): GenerateWeapon(partToSpawn as TankyWeapon); break; case (partTypes.Body): GenerateBody(partToSpawn as TankyBody); break; case (partTypes.Mobility): GenerateMobility(partToSpawn as TankyMobility); break; case (partTypes.Misc): GenerateMisc(partToSpawn as TankyMisc); break; } }
void GeneratePart(TankyParts partToSpawn, Transform Parent) { GeneratePart(partToSpawn, Parent, Vector3.zero, Vector3.zero); }