i have created a class in my class with a List of Variables
public class Achievement : MonoBehaviour
{
public static Achievement AchievementSystem;
[System.Serializable]
public class AchievementList
{
public Image icon;
public string display;
public string description;
public string ID;
public bool achieved;
}
for that i have created a variable in my current class:
[SerializeField]
public AchievementList[] achievementsList;
in my function i want to get the bool var "achieved" and check if its true:
public void Notification(string ID, bool achieved)
{
Achievement achievements = achievementsList.FirstOrDefault(x => x.ID == ID);
if (achievements.achieved == achieved) {
checkachieved = true;
}
And that's my problem. I get the error message "Achievement doesn't contain a definition for archieved" which sounds to me like Unity can't find the variables in my list even though I created one and should have easy access.
you are trying to call the variable bool achieved
of the class Achievement
. But bool achieved
is member of class AchievementList
. use AchievementList
instead of Achievement
:
public void Notification(string ID, bool achieved)
{
AchievementList achievements = achievementsList.FirstOrDefault(x => x.ID == ID);
if (achievements.achieved == achieved) {
checkachieved = true;
}}
You should rename your classes to clarify its usage.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.