private void Generate() { UOUtility.DestroyChildren(Generated); wayPoints.Clear(); float localSpacing = 0; Joint joint = null; for (int i = 0; i < segmentCount; i++) { var seg = UOUtility.Instantiate(segmentPrefab, Generated.transform); seg.transform.Translate(0, 0, localSpacing); var segRB = seg.GetComponent <Rigidbody>(); // we fix the first segment so that the vine won't fall if (i == 0) { firstSegment = seg; segRB.constraints = RigidbodyConstraints.FreezePosition; } // we attach the rigidbody to the joint of the previous segment if (joint != null) { joint.connectedBody = segRB; } joint = seg.GetComponent <Joint>(); // we save segments as way points for the spline deformation. wayPoints.Add(seg); localSpacing += segmentSpacing; } UOUtility.Destroy(joint); }
private void GeneratePhysicsGOs() { UOUtility.DestroyChildren(GeneratedPhysicsGO); wayPoints.Clear(); float localSpacing = 0; Joint joint = null; for (int i = 0; i < segmentCount; i++) { GameObject seg = UOUtility.Instantiate(segmentPrefab, GeneratedPhysicsGO.transform); seg.transform.Translate(0, 0, localSpacing); seg.tag = "Vine"; Rigidbody segRB = seg.GetComponent <Rigidbody>(); // we fix the first segment so that the vine won't fall if (i == 0) { segRB.constraints = RigidbodyConstraints.FreezePosition; seg.GetComponent <Collider>().enabled = false; //disable the collider on the first/center of the plant. _weed.vinesToPickBeforeDestorying.Enqueue(seg.transform); //store the first physics segment so the player can grab it with IK } else if (i == Mathf.Ceil(segmentCount / 2)) { //spawn object GameObject plantBlock = new GameObject("Generated Plant Block Collider") { layer = 11 }; plantBlock.transform.position = seg.transform.position; plantBlock.transform.SetParent(seg.transform); SphereCollider plantBlockCollider = plantBlock.AddComponent <SphereCollider>(); plantBlockCollider.radius = i * segmentSpacing; } else if (i + 1 == segmentCount) { // last segment deals damage to anything that has health healthDecrementer = seg.AddComponent <HealthDecrementer>(); healthDecrementer.damageAmount = damageAmount; healthDecrementer.damageRateInSeconds = damageRateInSeconds; healthDecrementer.damagedEnabled = false; } // we attach the rigidbody to the joint of the previous segment if (joint != null) { joint.connectedBody = segRB; } joint = seg.GetComponent <Joint>(); // we save segments as way points for the spline deformation. wayPoints.Add(seg); localSpacing += segmentSpacing; } UOUtility.Destroy(joint); }
private void GeneratePhysicsGOs() { UOUtility.DestroyChildren(GeneratedPhysicsGO); wayPoints.Clear(); float localSpacing = 0; Joint joint = null; for (int i = 0; i < segmentCount; i++) { GameObject seg = UOUtility.Instantiate(segmentPrefab, GeneratedPhysicsGO.transform); seg.transform.Translate(0, 0, localSpacing); Rigidbody segRB = seg.GetComponent <Rigidbody>(); // we fix the first segment so that the vine won't fall if (i == 0) { firstSegment = seg; segRB.constraints = RigidbodyConstraints.FreezePosition; seg.GetComponent <Collider>().enabled = false; //disable the collider on the first/center of the plant. } else if (i == Mathf.Ceil(segmentCount / 2)) { //spawn object GameObject plantBlock = new GameObject("Generated Plant Block Collider") { layer = 11 }; plantBlock.transform.position = seg.transform.position; plantBlock.transform.SetParent(seg.transform); SphereCollider plantBlockCollider = plantBlock.AddComponent <SphereCollider>(); plantBlockCollider.radius = i * segmentSpacing; } // we attach the rigidbody to the joint of the previous segment if (joint != null) { joint.connectedBody = segRB; } joint = seg.GetComponent <Joint>(); // we save segments as way points for the spline deformation. wayPoints.Add(seg); localSpacing += segmentSpacing; } UOUtility.Destroy(joint); }