More efficient way to compare objects in this manner?
I'm trying to reposition a player in a certain "spawn point" after a new scene is loaded. Basically, this happens when a player activates a trigger from a previous scene and the name of the previous scene is stored in a static variable. The new scene in which the player enters will have several different spawn point objects. The appropriate spawn point object will be chosen via a forloop and comparing each spawn point using the string of the previous scene that is stored.
This is my current algorithm. I was wondering if there is a better way to implement this? People have told me that comparing with strings should be avoided whenever possible.
"The appropriate spawn point object will be chosen via a forloop and comparing each spawn point using the string of the previous scene that is stored."
That tells me nothing about the problem you are trying to solve just a very vague description of how you solved it.
What is your algorithm actually doing? :)
It's just once at the start, and you probably don't have more than a dozen possible scenes each time, so no big deal for speed. I suppose you could get the scene numbers and use them ins$$anonymous$$d of strings. You could use an array and look it up by scene#, but that might be more trouble than it's worth.
As for general string-compare issues, yes, it can cause small problems. It's a tiny bit slower, and it's easy to misspell the name of a scene.
Your answer
Follow this Question
Related Questions
Trying to compare an input field with an int 0 Answers
compare string to string array[] 2 Answers
Cannot use operand '<' on type string and string 0 Answers
Sending Data from Arduino Uno to Unity 5 Answers
String to int conversion not working in ControllerCollider method although I am sure it is an int... 1 Answer