#pragma strict
var YourTexture : GUITexture;
var YourText: GUIText;
var YourAudio: AudioClip;
var PlayerScript;
function Start(){
PlayerScript = GameObject.Find("Player").GetComponent("Pick Up Key");
}
function Update(){
if(PlayerScript.gotKey)
{
}
else
{
function OnTriggerEnter(hit: Collider){
if(hit.gameObject.tag == "Player")
{
YourTexture.enabled = true; //make sure you set this to flase in the inspector as I said before else it will do nothing
YourText.enabled=true;
//play sound
//audio.clip=YourAudio;
//audio.Play();
}
}
function OnTriggerExit(hit: Collider){
if(hit.gameObject.tag == "Player")
{
YourTexture.enabled = false; //make sure you set this to flase in the inspector as I said before else it will do nothing
YourText.enabled=false;
}
}
}
}
I get some errors and I don’t know why. Can someone help?
Find can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
ArgumentException: Find can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
ObservatoryPrepDoorTrigger…ctor () (at Assets/Scripts/ObservatoryPrepDoorTrigger.js:6)
Assets/Scripts/ObservatoryPrepDoorTrigger.js(17,26): BCE0044: expecting (, found ‘OnTriggerEnter’.
Assets/Scripts/ObservatoryPrepDoorTrigger.js(17,41): BCE0043: Unexpected token: hit.
Assets/Scripts/ObservatoryPrepDoorTrigger.js(17,55): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/Scripts/ObservatoryPrepDoorTrigger.js(18,21): BCE0043: Unexpected token: if.