Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

please help, I don't get it!

Discussion in 'Scripting' started by TheBear66, Jun 11, 2020.

  1. TheBear66

    TheBear66

    Joined:
    Jun 9, 2020
    Posts:
    5
    Losing the will...

    I'm really hoping someone can help me. I have a fundamental function that i cannot get to work, I'm really hoping someone here is able to help.

    I'm trying to create a user interface that allows the user to put a String of text into an input field. There is a button next to this input field, and when the user presses said button after inputting some alphanumeric text. several things will happen.

    Firstly. I need the input field text to be 'cross referenced' against several (hundred) game objects' (sprites) names. Each of the sprites has a unique name.

    If there IS a sprite which shares the same name... I would very much like to spawn another sprite in one (scene)location and get it to move to the sprite that was originally identified.

    So that you can understand the overall effect. I am creating a grid of square sprites so that it forms a 'map' Using the grid reference (the sprites name) the user will be able to launch an airplane from off screen to attack said grid reference (sprite). I really hope this makes sense.

    I'm incredibly new to c# although i'm trying my best to catch up, and i've even got the bolt add-on to see if that would help. no luck as of yet. :-(
     
  2. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    you need to create a dictionary<string,sprite> that has all the names you want to check for, after the user enters the string you check if the dictionary contains it, if yes you do one thing, if not you do the other
     
    TheBear66 likes this.
  3. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Since you want to attack a grid cell, i assume you already have a grid of sprites defined which you can access. If so, adding to what @brigas said, i would probably store a Dictionary<string, Vector2>, where the Vector2 is the grid index of that sprite. This way you directly get both informations; the place to attack, and the option to get the sprite reference from the grid. In case the sprites can be moved around on the grid, remember to update the dictionary entry tho.
     
    TheBear66 and brigas like this.
  4. TheBear66

    TheBear66

    Joined:
    Jun 9, 2020
    Posts:
    5
    This is awesome guys thank you, I'll give it a try.