Game Development Reference
In-Depth Information
Texture Button (Script)
Drag the
Key
prefab object from the
Project
view
Key
Player
Drag the
Player
prefab object from the
Project
view
Note
Make sure that you use the prefab object from the
Project
view, not the
Hier-
archy
view. If not, the script might not work properly.
9. For the last step, we will go back to the
PlayerController_2D
script and the
_restartButton
variable to make this work. Let's open the
PlayerControl-
ler_2D
script and add the
OnTriggerEnter2D()
function as shown in the
highlighted script:
// Unity JavaScript user:
…
private var _restartButton : GUITexture;
…
function Awake () {
…
_restartButton =
GameObject.FindWithTag("RestartButton").guiTexture;
}
function Start () {
…
_restartButton.enabled = false;
}
…
function OnTriggerEnter2D (hit : Collider2D) :
IEnumerator {
if (!_gameEnd) {
…
if (hit.tag == "Door") {
if (_hasKey) {
…
_restartButton.enabled = true;