Ok, might sounds a bit complicated. But basically I created 3 monobehavior c# script,
- IdentityBuilding, this script is attached to every buildings game object, it holds building information such as anchorPoint(coordinate), building name, and building id, and etc
- IdentityWalker, this script is attached to all units game object (soldiers, and builders), it holds the unit information such as the unit type, unit name, and unit current coordinate
- scrHouse, this script is attached specifically to buildings that is a house-type game object. It holds house specific information, such as the amount of residents currently inside, and such
So on my home game object, there are two script, IdentityBuilding + scrHouse.
public class IdentityBuilding :
MonoBehaviour {public Vector2 anchorPoint; tk2dTileMap tileMap; List occupiedGrid = new List(); List adjacentGrid = new List(); public int type; public int panjang; public int lebar; public int buildingID; public string buildingName;
… }
/////////////////////////////////////////////////////////////////////////////////
public class IdentityWalker :
MonoBehaviour {public Vector2 anchorPoint; public bool isMoving = false; tk2dTileMap tileMap; public Vector2 inTile; bool initialdone = false; public bool brainInitialDone = false; public int walkerType; public string walkerName; public int walkerID; public int walkerState; tk2dSpriteAnimator animator; float BaseSpeed; Vector2 SpeedEast, SpeedNorth, SpeedWest, SpeedSouth; public IdentityBuilding buildingFrom; public IdentityBuilding buildingTo;
… }
/////////////////////////////////////////////////////////////////////////////////
public class scrHouse : MonoBehaviour → http://hastebin.com/igitacasun.cs
On my unit, specifically, the IdentityWalker class, it also stores the building where this unit come from (buildingFrom), and the building where it’s heading to (buildingTo). buildingFrom is assigned upon instantiating this unit prefab.
Now my question is, whenever I change the value of buildingFrom inside my unit, for example the anchorPoint (coordinate), it will affect the original building itself even though the thing that im changing is the buildingFrom variable inside my unit, why is that?
(ex: GameObjectoftheUnit.buildingFrom.anchorPoint = Vector.zero ), the actual house coordinate moves to coordinate 0,0
Thanks!