This question was
closed Nov 10, 2015 at 04:24 PM by
oen432 for the following reason:
The question is answered, right answer was accepted
Class extension (player.STR to player.Stats.STR)
Here is my example class called Player
public class Player {
public int STR;
public int INT;
public int DEX;
public int VIT;
public Player() {
STR = 1;
INT = 1;
DEX = 1;
VIT = 1;
}
public Player Stats {
get {
return STR;
return INT;
return DEX;
return VIT;
}
set {
STR = value;
INT = value;
DEX = value;
VIT = value;
}
}
}
public Player player = new Player();
I was using this by calling: player.STR
I want to use this by calling: player.Stats.STR
It's kind of working in code but after compilation I have this error:
Assets/PlayerAI.cs(62,33): error CS0029: Cannot implicitly convert type `int' to `PlayerAI.Player'
How to fix this? What's wrong with this code?
Comment
Best Answer
Answer by oen432 · Nov 10, 2015 at 04:25 PM
Solved.
public class Player
{
public class Statistics
{
public int STR;
public int INT;
public int DEX;
public int VIT;
}
public Player()
{
this.Stats = new Player.Statistics()
{
STR = 1,
INT = 1,
DEX = 1,
VIT = 1
};
}
public Statistics Stats {get;set;}
}
Follow this Question
Related Questions
Call a method of a class derived from MonoBehaviour from a class that isn't. 1 Answer
How to add a Type to a Class in Javascript? 1 Answer
Can't access methods from class 1 Answer
How do I get the code to Find whichever object is active with FindObjectOfType? 1 Answer
C# Find specific object by getting one of its variables 0 Answers