public void ParentalGrowth(float lengthScale, float widthScale) { if (transform.parent != null) { TreeLimb parentLimb = transform.parent.GetComponent <TreeLimb>(); if (parentLimb != null) { parentLimb.SetGrowTargetLength(lengthScale); parentLimb.SetGrowTargetWidth(widthScale); parentLimb.ParentalGrowth(lengthScale, widthScale); } } }
void SpawnNewLimb() { bool bLimb = false; int tries = 0; while (!bLimb && (tries < (limbList.Count * limbList.Count))) { tries++; int parentLimbIndex = Random.Range(0, limbList.Count); if ((limbList[parentLimbIndex] != null)) { TreeLimb parentLimb = limbList[parentLimbIndex]; float parentLength = parentLimb.GetLimbLength(); float minimumLength = Mathf.Clamp(Mathf.Sqrt(parentLength), 0f, parentLength * 0.9f); float sproutLimbHeight = Random.Range(minimumLength, parentLength); Vector3 sproutPosition = parentLimb.transform.position + (parentLimb.transform.up * sproutLimbHeight); Quaternion spawnRotation = Quaternion.Euler(new Vector3(0f, 0f, Random.Range(-50f, 50f))); GameObject stem = Instantiate(limbPrefab, Vector3.zero, spawnRotation); stem.transform.SetParent(parentLimb.transform, false); stem.transform.position = sproutPosition; TreeLimb stemLimb = stem.GetComponent <TreeLimb>(); stemLimb.SetLimbLine(true, sproutPosition, stemLimb.transform.up * 0.1f); stemLimb.AttachToRb(parentLimb.GetComponent <Rigidbody2D>()); stemLimb.SetColliderEnabled(true); stemLimb.SetGrowTargetLength(parentLimb.GetLimbLength() * 0.36f); stemLimb.SetGrowTargetWidth(0.02f); stemLimb.ParentalGrowth(1.1f, 1.02f); PlantPhysics pPhysics = stemLimb.GetComponent <PlantPhysics>(); pPhysics.SetNaturalDirection(stemLimb.transform.up); stemLimb.ImbueLeaf(); limbList.Add(stemLimb); bLimb = true; } } }
public void Spend() { if (targetLimb != null) { limbPrototype.transform.SetParent(targetLimb.transform); limbPrototype.AttachToRb(targetLimb.GetComponent <Rigidbody2D>()); limbPrototype.SetColliderEnabled(true); limbPrototype.SetGrowTargetLength(targetLimb.GetLimbLength() * 0.36f); limbPrototype.SetGrowTargetWidth(0.02f); limbPrototype.ParentalGrowth(1.1f, 1.05f); PlantPhysics pPhysics = limbPrototype.GetComponent <PlantPhysics>(); pPhysics.SetNaturalDirection(limbPrototype.transform.up); limbPrototype.ImbueLeaf(); closeupUI.SetActive(false); bTargeting = false; Destroy(gameObject); } }