function Update ()
{
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Input.GetMouseButtonDown(0))
{
if (Physics.Raycast (ray, hit, Mathf.Infinity))
{
if(hit.transform==door)
{
//check if quest is completed
//if yes, loadscene
Instantiate(explosion,transform.position,transform.rotation); //create an explosion
Application.LoadLevel("quest1");
Destroy(door);
}
}
}
}
The game flow this way: Player is being blocked by the door, in order to open the door, player have to click the door. So after clicking the door, they will be request to finish a quest before the door is open for them to go in. i use Destroy(door) but the door gameobject are not being destroyed. I do not know why. Any ideas how i could go about doing this? Is there any other way to do it?
Try putting Destroy(door); before the Application.LoadLevel(“quest1”); Also just saying destroy door may not work you may need to create a reference to the door. Like var door :GameObject; Not positive on that though.
Is door a Transform or a GameObject? You’re treating it 2 different ways.
The door is a Transform.
In order to destroy the door, i add in new variable door 1 : GameObject; I do not know whether it is the correct way to do it.
Just Destroy(door.gameObject);
Yes, thank you. It work properly.
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Input.GetMouseButtonDown(0))
{
if (Physics.Raycast (ray, hit, Mathf.Infinity))
{
for (var j : int=0; j < 9; j++)
{
if(hit.transform==door[j])
{
//check if quest is completed
[B][COLOR="red"]// how to do i change to load different quest? like door 1, load quest1; door 2 load quest 2..[/COLOR][/B].
Application.LoadLevel("quest1");
//if yes, loadscene
//if(questControl.finishQuest[j])
Instantiate(explosion,transform.position,transform.rotation); //create an explosion
Destroy(door[j].gameObject);
}
}
}
}
}
Basically i have 8 doors in the games. So i decide to declare as var door : Transform[ ];
So what i am trying to do is, player can only start at the first door, when player click on first door, load quest1, player have to complete quest1 in order to open the door as mentioned earlier. So i will have a static var finishQuest to check if the quest is completed. Then the gamecontrol will check if the finishQuest is true, if yes, destroy door1.