Weird Variable Behavior

I am trying to write a RPG-style inventory handler.

Each object that can be picked up by the player has a script attached to it which contains variables for the object information (name, weight, value, etc…). When an object is picked up, its information is recorded by the inventory handler script then the object is destroyed. When the player drops the object, a new copy is instantiated and the information recorded in the inventory is assigned to the new copy.

Now is where the problem occurs… The variables containing the object information in the script attached to the new object and the variables which represented the object in the inventory handler script are somehow linked. For example, if I alter the weight variable in the object script with the inspector, the corresponding weight variable in the inventory script is changed to the same value. Likewise, if I alter the one of the weights through the script, the other is also changed.

What can I do to not have the two linked like this?

Are you using static variables? If so, don’t.

–Eric

No static variables involved.

I think I figured out my problem. I am trying make a copy of a class and instead I am getting a reference similar to the problem solved in this thread involving copying an array:

http://forum.unity3d.com/viewtopic.php?t=30569

here’s what i’d like to accomplish…

class object {
	var Name : String;
	var Weight : int;
	var value : int;
}

var originalObject : object;
var newObject : object;

function copyInfo () {
	newObject = originalObject;
}

is there something similar in js to System.Array.Copy to copy a class variable?

var originalObject = new object();
originalObject.name = "Bob";
var newObject = originalObject.MemberwiseClone();
print (newObject.name);

–Eric

Worked great. Thank you!