Hello, so im making this pokemon clone.
I created a class pokebon which holds every stat.
Then i created a variable called pokebon list of type pokebon which holds every single pokebon stats.
The problem is when i make the character get a pokebon. I copy the class to another one in the objects inventory. The class isnt copied, but its sent as reference, so each time it levels up or changes any attribute the pokebon list which holds the base info changes too!
Is there a possibility to transfer the variables of a class to another without passing it as reference and without handwriting every single variable to another??
THIS IS THE CODE WHERE I CREATED THE POKEBON CLASS AND ALSO WHERE I ADD POKEBONS TO THE INVENTORY
#pragma strict
var LastPosition:Vector3 = Vector3.zero;
var LastOneWasDoor:boolean = false;
var ChatBoxProgress:boolean[];
var Inventory:InventoryClass;
var Sounds:AudioClip[];
var BattleInfo:BattleInfoClass;
class InventoryClass{
var Item:item[];
var Money:int;
var PokeBons:PokeBon[];
};
class BattleInfoClass{
var CharacterID:int;
var CharacterID2:int;
var WildBattle:boolean;
var RivalPokeBon:int;
var RivalLVL:int;
};
class item{
var Name:String;
var Quantity:int;
var Price:int;
var Usable:boolean;
var ID:int;
};
class PokeBon{
var ID:int;
var Pokebon:GameObject;
var Health:int;
var Mana:int;
var Level:int;
var Experience:int;
var Name:String;
var Strength:int;
var Dexterity:int;
var MagicDamage:int;
var AgileBoost:boolean;
var Stab:boolean;
var SpitAcid:boolean;
var FrostBolt:boolean;
var FireBolt:boolean;
var Tornado:boolean;
public function ReturnPokeBon(){
return this;
}
};
function Start () {
DontDestroyOnLoad(this.gameObject);
}
function Awake(){
for(var ChatBox in GameObject.FindGameObjectsWithTag("Chat")){
if(ChatBoxProgress[ChatBox.GetComponent(TriggerChatBox).ChatBoxN]){
ChatBox.GetComponent(TriggerChatBox).Triggered = true;
}
}
}
function Update () {
}
function GetLastPosition(){
if(LastPosition != null){
return LastPosition;
}else{
return Vector3.zero;
}
}
function SetLastPosition(Door:boolean,Pos:Vector3){
LastPosition = Pos;
Pos += Vector3.forward *0.3;
}
function TriggerChat(ChatNum:int){
ChatBoxProgress[ChatNum] = true;
print("DEACTIVATED CHATBOX");
}
function AddPokeBon(ID:int){
var i:int = 0;
while(Inventory.PokeBons*.Level != 0){*
-
i++;*
- }*
- Inventory.PokeBons.SetValue((this.gameObject.GetComponent(PokeBonList).PokeBonlist[ID]),i);*
_ if(Inventory.PokeBons*.Level == 0){_
_ Inventory.PokeBons.Level = 1;
}*_
}
function InitializeBattle(WildBattle:boolean,RivalPokemon:int,LVL:int){
* if(WildBattle){*
* BattleInfo.CharacterID = -1;*
* BattleInfo.CharacterID2=-1;*
* BattleInfo.WildBattle=true;*
* BattleInfo.RivalLVL = LVL;*
* BattleInfo.RivalPokeBon = RivalPokemon;*
* Application.LoadLevel(“Fight”);*
* }*
}
function InitializaBattle(CharacterID:int,CharacterID2:int){
}
function ReturnBattleInfo(){
* return (BattleInfo);*
}