- Home /
How can I pick 3 random Gameobjects from an array and then shrink them to a point?
I want to pick a certain amount of gameobjects from an array based on tags and then shrink them down into their center. How would I calculated the center of three objects that have. if Possible how would I do it to three that had collided with each other while chasing the player.
Answer by GilbertoBitt2 · Nov 22, 2016 at 08:25 PM
i don't need calculate the center.. u can use a lerp on the scale of it... will to the same effect with less effort...
Wouldn't that shrink it along its local scale I want it to shrink along the local scale of three objects to the center point
Answer by Axtrainz · Nov 22, 2016 at 10:46 PM
This may help you: How to find the center of three or more objects
Finding the median between the objects is probably the best solution.
Not really. The center is in the mean, not the median.
this is the code in C# but it has errors and I am confused on how to fix them @Axtrainz
using UnityEngine; using System.Collections;
public class Enemy$$anonymous$$anager : $$anonymous$$onoBehaviour {
public GameObject tinyBird;
public Vector3 center;
// Use this for initialization
void Start () {
tinyBird = GameObject.CreatePrimitive(PrimitiveType.Sphere);
tinyBird.transform.localScale = Vector3(0.2f, 0.2f, 0.2f);//Non invocable member Vector3 cannot be used like a method;
}
// Update is called once per frame
void Update () {
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
PickObject();
}
}
public Vector3 PickObject(GameObject[] gos)//how to fix not all code paths return a value
{
if (gos.Length == 0)
{
return Vector3.zero;
}
if (gos.Length >= 1)
{
return gos[0].transform.position;
}
Bounds bounds = Bounds(gos[0].transform.position, Vector3.zero);//ounds non invocable memeber
for (var i = 1; i < gos.Length; i++)
{
bounds.Encapsulate(gos[i].transform.position);
return bounds.center;
}
}
}
Your answer

Follow this Question
Related Questions
How to remove objects from a list ? 3 Answers
How do you save GameObject[]? 1 Answer
Can't add GameObjects to ArrayList 1 Answer
Keep adding targets to a list 2 Answers
Removing objects from an array 2 Answers