In space there is great distances between planets…
You can barely see them since the stars make the planets “fade” in as a “star”
Same goes for my space game.
So my question is:
How do you make a in game search function that you can access via a klick button to type for example “Jupiter”,
and then it search for a object with tag “Jupiter”, and when it find the planet a button shows up that if you klick on turns your space ship to point at the object “jupiter”
I guess this sounds messy…but this is the best way i can explain it.
I think a generic Dictionary might be a better approach than a generic List. string/gameobject key pair for all the things in the game you want to be able to search for.
I dont know if im on the right way here with the code? but im getting error
The type or namespace name `List`1' could not be found. Are you missing a using directive or an assembly reference?
using UnityEngine;
using System.Collections;
public class PlanetSearch : MonoBehaviour {
private GameObject planetList = new List<GameObject>();
// Use this for initialization
void Start () {
}
void SearchPlanet(string planetName)
{
foreach(var planet in planetList)
{
if (planet.name == planetName)
{
//You have a match! Now do stuff
}
}
}
I have a video in my tutorial series (link in signature) on Lists. You can check it out there for better understanding. Also, I have a full fundamentals, intermediate, and 30% advanced series on my playlist. (Advance playlist is still on going) I recommend checking it out. It will help you
Oh! i deleted “List” when i typed “private” that should been “public” lol.
Now i just need to figure out how to make that canvas button appear when i activate the “PlanetCatalog” image + a function to be able to type and execute the searhing.
I had some trouble with that canvas button earlier today since it have a “image, button, text” script that must be checked/unchecked at same time on button klick . Any tips?
I will take a look at your tutorials, thanks for that tip!