- Home /
Question by
wrcboy39 · Aug 30, 2021 at 03:47 PM ·
c#detectionfind-gameobject
find the highest gameobject of stacked gameobjects
i am new and i have a game that stack game objects on top of each other and i want to find the gameobject with the highest y value so i can move the camera up to the highest one
Comment
Answer by logicandchaos · Aug 30, 2021 at 04:57 PM
Just check all the y values. You can add all the transforms to a list, iterate through and check which has the highest y value. List stackedObjects;
float highestYValue=0;
foreach(Transform t in statckedObjects)
{
if(t.position.y>highestYValue)
highestYValue=t.position.y
}
All you have to do is populate the list.
Alternatively you could probably get the reference as you place the block.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Detect tag in C# 1 Answer
How to check if an empty GameObject is inside an object? 2 Answers
Weapon System with collide detection (Helps with script pls)!!! 0 Answers