- Home /
How do I enter/exit a buildingin Unity3D?
Hi, I am new to unity. I'm making a Pokémon based game in unity 3d for school. I want to make a few buildings which i can enter. I was able to make a script which when I press e on the trigger it would transfer me over to the inside building scene. However, I can only load the scene. My character doesnt transfer over to the scene. My question is: How can i spawn my character inside and back outside the house? Also, how do i assign the spawnpoint for the character?
Thanks.
Answer by Vegit0n · Oct 18, 2017 at 05:05 PM
This is the code i used to enter the building:
using UnityEngine; using System.Collections;
public class OnTriggerLoadLevel : MonoBehaviour { public GameObject guiObject; public string levelToLoad; void Start() { guiObject.SetActive(false); }
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
guiObject.SetActive(true);
if (guiObject.activeInHierarchy == true && Input.GetButtonDown("Use"))
{
Application.LoadLevel(levelToLoad);
}
}
}
void OnTriggerExit()
{
guiObject.SetActive(false);
}
}
Your answer
Follow this Question
Related Questions
Game object spawning, spawn conditions and spawning location problems. 1 Answer
[Help] How Do I Randomly Spawn Game Objects On Specific Coordinates? 3 Answers
Spawn Object Outside of Radius 3 Answers
Prevent object from spawning at a spawn point twice in a row? 3 Answers
Spawning player at appropriate point in random model of a city using only the mesh data. 1 Answer