- Home /
Can someone tell me what is wrong with this?
characterList [index].tag =('Player');
Im trying to tag the gameobjects in the array as player tag.
Answer by Lysander · Jan 03, 2018 at 05:50 AM
Should probably be characterList[index].tag = "Player";
No need for the parentheses there.
Ok, but can I tag the key "CharacterSelected" in this code?
index = PlayerPrefs.GetInt ("CharacterSelected");
I don't see why not, but only if you check that the PlayerPrefs key exists, and if you're absolutely sure the array is identical to the one that existed when you saved that value to PlayerPrefs previously. It may be far safer to save a string for the character name (or some sort of static ID number for the character in question, which does not change between sessions or scenes) and then find the element in the array for that character, ins$$anonymous$$d of storing an index.
Answer by Alex_404 · Jan 03, 2018 at 05:57 AM
There is no need of parentheses while assigning tags and any strings. It should be working like this characterList [index].tag ="Player";
Your answer
Follow this Question
Related Questions
Unity c# indexoutofrangeexception: array index is out of range 1 Answer
Using PlayerPrefs to save a C# Generic List 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Array index is out of range 2 Answers