Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by birns92 · Jun 23, 2016 at 10:14 PM · c#gameobjectcollidersearch

Search GameObjects while in game

I would like to add a in game search engine that searches for gameobjects and selects the gameobject using its' collider.

Take my simple example with four blocks alt text

Lets say I add a Input Text Field and a search button like this:

alt text

Currently I have a highlight gameobject script and also this upcoming script : which displays the gameobjects name on screen once selected.

 using UnityEngine;
 using System.Collections;
 
 public class Cube : MonoBehaviour
 {
     public GUISkin Border;
     float native_width = 720;
     float native_height = 1280;
     public bool CubeInfo = false;
     public GUIStyle style;
     string Cube_Name = "".PadLeft(100);
     public bool Cube_Buttons = false;
     private Rect NameRect;
     void Start()
     {
         Cube_Name = gameObject.name;
         SetGUIAspectRatio();
     }
 
     void OnMouseDown()
     {
         Display();
     }
 
     //Display Object Name
     private void Display()
     {
         Cube[] Cubes = FindObjectsOfType(typeof(Cube)) as Cube[];
         foreach (Cube o in Cubes)
         {
             o.Cube_Buttons = false;
         }
 
         Cube_Buttons = true;
     }
 
     //Sets the Aspect Ratio of GUI
     void SetGUIAspectRatio()
     {
         NameRect = new Rect(75, 0, Screen.height, 75);
     }
 
     void OnGUI()
     {
         float rx = Screen.width / native_width;
         float ry = Screen.height / native_height;
         GUI.matrix = Matrix4x4.TRS(new Vector3(0f, 0f, 0f), Quaternion.identity, new Vector3(rx, ry, 1f));
         if (Cube_Buttons)
         {
             // Make a Name Button
             GUI.Button(NameRect, Cube_Name.PadRight(50), style);
         }
     }
 }

Using C# what would I need in a script that if I type "Yellow" in the Input Text field and click select, the Yellow box is selected and the name is displayed using the same script as listed above. Since I am just starting this off, I think a complete answer from start to finish is to much to ask for without providing preexisting scripts to piggyback off of. A Tutorial, or a point in the right direction with a link would be much appreciated

block.jpg (117.8 kB)
search.jpg (147.0 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Googly_Derpy · Jun 24, 2016 at 05:02 AM

GameObject selected = GameObject.Find(inputText);

Comment
Add comment · 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
0

Answer by Googly_Derpy · Jun 24, 2016 at 05:02 AM

GameObject selected = GameObject.Find(inputText);

Comment
Add comment · 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
0

Answer by Bunny83 · Jun 23, 2016 at 10:42 PM

Well, this is much simpler as you might think, however the biggest open question is what you understand by "select" / "selected".

To actually find a gameobject be name you can simply use GameObject.Find(). It will return the reference to the gameobject with the entered name if one exists. Again the open question is how you want to represent the "selection" visually.

Comment
Add comment · Show 1 · 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 birns92 · Jun 23, 2016 at 11:09 PM 0
Share

I updated my question, hopefully that makes it more clear.

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

168 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 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

Distribute terrain in zones 3 Answers

Destroying Game Object On MouseButtonDown + Distance Collision 0 Answers

I need help with triggers 1 Answer

Simple In game search field 2 Answers

Array of colliders/triggers 0 Answers


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