I have a small problem and I can not resolve it.
I have a class (array 0 ~ 999) called pTest
, it is already instantiated all right.
After I instantiate I copy a structure that is from the player (contains name, level information, etc.) of another class to bind within pTest
.
For example:
pTest[0].Player = g_kNPCGener.kMonster[0].MOB;
If I do this in a method:
pTest[0].Player = g_kNPCGener.kMonster[0].MOB;
pTest[1].Player = g_kNPCGener.kMonster[0].MOB;
pTest[0].Player.Name = "Grim";
pTest[1].Player.Name
will also be set to "Grim".
Structure pTest[0].Player
is the same structure (struct) of Monster.List[0].NPC
;
public class TmController
{
public MobTest[] pTest = new MobTest[1000];
// methods..
public void init()
{
pTest[0].Player = g_kNPCGener.kMonster[0].MOB;
pTest[0].Mode = 1;
pTest[1].Player = g_kNPCGener.kMonster[0].MOB;
pTest[1].Mode = 1;
}
public TmController()
{
for (int i = 0; i < pTest.Length; i++)
{
pTest[i] = new MobTest();
}
}
}
public class MobTest : TmController
{
public STRUCT_MOB Player;
public int Mode;
public MobTest()
{
Player = STRUCT_MOB.Clear();
Mode = 0;
}
}
If you change the Mode
property of the object pTest[0]
, for example: pTest[0].Mode = 5
, it does not change pTest[1].Mode
.
How do I fix this?