Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- //Holder styr på at tilføje mm. characters.
- public class CharacterManager : MonoBehaviour {
- public static CharacterManager instance;
- //Characters skal være under characterPanel.
- public RectTransform characterPanel;
- //Liste med alle characters i scenen.
- public List<Characters> characters = new List<Characters>();
- //Nem måde at søge efter vores characters.
- public Dictionary<string, int> characterDictionary = new Dictionary<string, int>();
- void Awake()
- {
- instance = this;
- }
- //Prøver at finde en character med det givne navn fra character listen.
- public Characters GetCharacter(string characterName, bool createCharacterIfDoesNotExist = true, bool enableCreatedCharacterOnStart = true)
- {
- int index = -1;
- if (characterDictionary.TryGetValue (characterName, out index))
- {
- return characters[index];
- }
- else if (createCharacterIfDoesNotExist)
- {
- return CreateCharacter(characterName, enableCreatedCharacterOnStart);
- }
- return null;
- }
- public Characters CreateCharacter(string characterName, bool enableOnStart = true)
- {
- Characters newCharacter = new Characters(characterName, enableOnStart);
- characterDictionary.Add(characterName, characters.Count);
- characters.Add(newCharacter);
- return newCharacter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement