I am working on user account creation for a game I am working on in the Unity engine. I figured the best way to achieve this would be to have an object added to an ArrayList (if I am not mistaken, with an ArrayList you do not need to define the size of the Array). I set the object properties (the base stats that I want every new player to have). When I get to the foreach loop in the accessInfo segment of code, I get stuck trying to reference a particular property of the object (for instance, playerAgility which is set to 30, for demonstration purposes). Any help would be great. Thanks!
newProfile script:
using UnityEngine;
using System.Collections;
public class newProfile : Profile
{
ArrayList newprofile = new ArrayList();
public void newplayer(string input)
{
newprofile.Add(new Profile(10, 20, 30, 40, 50, input));
}
public void accessInfo()
{
foreach (Profile element in newprofile)
{
// Debug.Log(need to access the values set for the profile);
}
}
public newProfile(string input)
{
newplayer(input);
accessInfo();
}
}
Profile script (A sample as not to create a massive post):
public class Profile
{
private Profile user;
private int PROFILE_STAMINA, PROFILE_STRENGTH, PROFILE_AGILITY;
private int PROFILE_INTELLECT, PROFILE_SKILL,PROFILE_MASTERY;
private string ProfileName;
public Profile(int Stamina, int Strength, int Agility, int Intellect, int Skill, string username)
{
user = new Profile();
profileStamina = Stamina;
profileStrength = Strength;
profileAgility = Agility;
profileIntellect = Intellect;
profileSkill = Skill;
userName = username;
}
public int profileStamina
{
get { return PROFILE_STAMINA; }
set { PROFILE_STAMINA = value; }
}
//Identical setters and getters for the remaining stats
public string userName
{
get { return ProfileName; }
set { ProfileName = value; }
}
}
Debug class:
public class debug : MonoBehaviour
{
void Start()
{
new newProfile("working");
}
}