what I am trying to achieve is when I click on a block I want a girl to appear in front of me. I have already added the object to the game so I would like it to just appear when this block is clicked and then after about 5 seconds disappear. But before I can address the time I can’t get the girl to not be visible when the game starts. This is what I have so far:
var Girl : GameObject;
function Start(){
Girl.enabled = false;
}
function OnMouseDown(){
Girl.enabled = true;
}
For some reason when I start my game the girl is there before I click the block. I have the variable set right in Unity inspector so where am I going wrong?
Go to your project pane. Create a new folder within the assets folder named “Prefabs”. Then go to that new prefab folder, right click, then choose “Create > Prefab”. Name the prefab. Drag the girl from the scene pane onto the new prefab in the Project pane. You can now delete the girl from the scene. Then you would need to Instantiate the prefab on click event.
var Girl : GameObject;
var spawnPoint : Transform;
function OnMouseDown()
{
var clone;
clone = Instantiate(Girl, spawnPoint.position, Quaternion.identity);
Destroy(clone.gameObject, 3);
}
you can experiment around with the position and rotation of the girl prefab. We need to create the new var clone because we only want to destroy the clone of the prefab, not the actual asset. This should get you on the right path.