- Home /
Question by
JackBid · Mar 22, 2013 at 04:38 PM ·
gameobjectinstantiateprefabs
Instantiating gameObjects and prefabs issues.
I want to make it so when a button is clicked the gameObject saved to a variable changes and instantiates a different prefab. However the prefab that is loaded seems to be dependent on what is assigned to the script in the inspector. How can I change what is assigned to it from code?
This is what I have so far:
var tile = (Resources.Load("prefabs/up"));
function OnMouseOver(){
var tile = (Resources.Load("prefabs/up"));
if(Input.GetMouseButtonDown(0)){
if(gameObject.transform.tag == "tile"){
var p = Vector3(transform.position.x, transform.position.y - 0.4, 0);
Instantiate(tile, p, Quaternion.Euler(0, 0, 90));
destroy.money -= 50;
}
}
}
So when I click a button I want the tile variable to change to a different prefab. Resources.Load does not seem to work and as I said earlier, the prefab that load appears to be dependent on what is selected from the inspector.
Comment
from inspector you mean project tab of hiearchy?
BTW what's this
destroy.money -= 50;
that's just a static variable from a script called destroy, it just decreases the money the player has when you place a block