Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by perendl · Mar 17, 2016 at 09:22 PM · c#cameraobjectscoordinates

Search for Object with largest y-Coordinates

Hello there! I want to search for an Object in Objects with the same Tag who has the highes / largestt y-coordinates in the scene. I know i could do it with put the objects when they spawn in an array and then ckeck with loops the highest position, but may there is a better way and smoother way. I need this because my Camera needs to go move up on the y-coordinates if the objects pile and become more and more higher, other hints for my solutions would be great aswell. :)

Ty for reading and coming answers, excuse my bad english.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jgodfrey · Mar 17, 2016 at 10:39 PM

Well, something is going to have to iterate through the objects in question and find the one with the largest Y value. You should be able to find the objects in question using something like:

  GameObject[] gos = GameObject.FindGameObjectsWithTag("yourTag");

Then, just spin through the objects in the returned array and find the one you're interested in.

Alternatively, you could probably use some LINQ to get what you want. Caution - typed directly into the forum and completely untested...

 GameObject go = GameObject.FindGameObjectsWithTag("yourTag")
    .OrderByDescending(go => go.transform.position.y).First();

If you choose to use some LINQ, you'll need to add a "using System.Linq;" to the top of your file.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image perendl · Mar 17, 2016 at 10:57 PM 0
Share

Yeah i got this aswell 10$$anonymous$$ after i opened this thread, but my problem is now that i dindt get how i can move my camera and cameraobject smoothly if an object become higher y-coord. in my code it just instantly changes the position and its not good cause the physics are not working if it jumps so fast between the positions.

  public Vector3 Hoehstgelegen;
     public GameObject[] Liste { get; private set; }
     public GameObject Boden;
 ...
 ...
 ...
 
 Liste = GameObject.FindGameObjectsWithTag("Objekt1").OrderBy(liste => -liste.transform.position.y).ToArray();
         Hoehstgelegen = new Vector3(Liste[0].transform.position.x, Liste[0].transform.position.y, 0);
 
         float distanz;
         distanz = Vector3.Distance(Boden.transform.position, Hoehstgelegen);
 
         transform.position = new Vector3(transform.position.x,4+distanz,transform.position.z);


avatar image perendl perendl · Mar 17, 2016 at 11:02 PM 0
Share

got it!

 float distanz;
         distanz = Vector3.Distance(Boden.transform.position, Hoehstgelegen);
         Vector3 testen;
         testen = new Vector3(transform.position.x, 4 + distanz, transform.position.z);
 
         transform.position = Vector3.$$anonymous$$oveTowards(
             transform.position,
             testen,
             Time.deltaTime);
     }
avatar image jgodfrey · Mar 17, 2016 at 11:00 PM 0
Share

Do yourself a favor and open a new thread as you now have a completely different question.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

129 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Show Text where user clicks in a panel,Show text where User clicks 0 Answers

Toogle Parent to Camera Function - Google Cardboard 0 Answers

Call function of a MonoBehaviour class in another class 0 Answers

How can I change a function from another script? 1 Answer

Top Down Camera View Problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges