- Home /
How do I remove a GameObject var?
If this is my script, how do I remove the game object? I need to rephrase though. How do I remove it from the property window? When I click on whatever the script is in, the game object will want me to assign something to it. So I do. Now how do I remove that game object from that spot? Also, how do I add one to it? I will answer all answers hopefully in less than an hour after posted if you have a question.
var Product : GameObject;
I've tried to understand this question, but am struggling....
If you want to have a variable in your script, but hide it in the Inspector, declare it as a private variable :
private var Product : GameObject;
Now how do I remove that game object from that spot? Also, how do I add one to it? do you want to store more than one object in an array? I have no idea what you are asking, sorry.
do u want to add a gameObject via script or by the inspector? i dont get it
I thought it might sound confusing. I want fo change objects out of the inspector. I want to take a gameobject variable and change the gameobjects in it. Like lets say product1 is in var object : gameobject. I want to put product2 in place of product1
var product1 : GameObject;
var product2 : GameObject;
function SwapObjects()
{
var swapper : GameObject = product1;
product1 = product2;
product2 = swapper;
}
Is this what you meant? So if you call SwapObjects(); whatever is in product 1 and 2 will be swapped.
EDIT : EmptyObjects() gives null values for product1 & 2
var product1 : GameObject;
var product2 : GameObject;
function SwapObjects()
{
var swapper : GameObject = product1;
product1 = product2;
product2 = swapper;
}
function EmptyObjects()
{
product1 = null;
product2 = null;
}
I thought it through, and what I was thinking wont work. Sorry!
Answer by Eric5h5 · Sep 04, 2012 at 05:17 PM
To delete an item, either click the selector and select "none" from the list, or press the delete key. To replace an item, either click the selector and select another item from the list, or drag'n'drop another item on the slot.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080616im_/https://answers.unity.com/themes/thub/images/avi.jpg)