When I try to pick up a key in this script it doesnt.
The error is:
MissingMethodException: UnityEngine.GameObject.BackToNormal
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object args)
Boo.Lang.Runtime.RuntimeServices+c__AnonStorey15.<>m__9 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object args, System.Type scriptBaseType)
Key.Update () (at Assets/Key.js:51)
And:
MissingMethodException: UnityEngine.GameObject.TextureChange
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object args)
Boo.Lang.Runtime.RuntimeServices+c__AnonStorey15.<>m__9 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object args, System.Type scriptBaseType)
Key.Update () (at Assets/Key.js:34)
The code is in three parts the key script (obviously), the Cross-Hair and finally the door.
The Key Script:
var Length : float = 3;
static var HaveKey : boolean = false;
var ShowText : boolean = false;
var Text : String = "You picked up a key";
var FirstPersonController = GameObject;
var Crosshair = FirstPersonController;
var other : GameObject;
function Update () {
var hit : RaycastHit;
var ray : Ray = camera.ViewportPointToRay (Vector3(0.5,0.5,0));
var fwd = transform.TransformDirection (Vector3.forward);
Debug.DrawRay(transform.position, fwd * Length, Color.green);
if(Physics.Raycast(ray, hit, Length))
{
hitObject = hit.collider.gameObject;
if(hitObject.gameObject.tag == "Key")
{
other.GetComponent(Crosshair).TextureChange();
if(Input.GetKeyUp(KeyCode.E))
{
GetKey();
Destroy(hitObject);
}
}
else if(hitObject.gameObject.tag == "Untagged")
{
other.GetComponent(Crosshair).BackToNormal();
}
}
else if(!Physics.Raycast(transform.position, transform.forward, hit, Length))
{
other.GetComponent(Crosshair).BackToNormal();
}
}
function GetKey(){
HaveKey = true;
ShowText = true;
yield WaitForSeconds(3);
ShowText = false;
}
function OnGUI(){
if(ShowText)
{
GUI.Label(Rect(Screen.width /2 -62.5, Screen.height /2 + 50, 200, 100), Text);
}
}
THE CROSS-HAIR SCRIPT:
var CrosshairTexture : Texture2D;
var UseTexture : Texture2D;
var NormalTexture : Texture2D;
var ShowCrosshair : boolean = true;
var CanChange : boolean = false;
function Start()
{
Screen.lockCursor = true;
}
function OnGUI()
{
if(ShowCrosshair == true)
{
GUI.Label(Rect((Screen.width - CrosshairTexture.width) /2, (Screen.height -
CrosshairTexture.height) /2, CrosshairTexture.width, CrosshairTexture.height), CrosshairTexture);
}
}
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == "Door")
{
CanChange = false;
CrosshairTexture = UseTexture;
}
}
function OnTriggerExit(other : Collider)
{
if(other.gameObject.tag == "Door")
{
CanChange = true;
CrosshairTexture = NormalTexture;
}
}
function TextureChange(){
if(!CanChange)
{
CrosshairTexture = UseTexture;
CanChange = true;
}
}
function BackToNormal(){
if(CanChange)
{
CanChange = false;
CrosshairTexture = NormalTexture;
}
}
LOCKED DOOR SCRIPT:
var IsOpen : boolean = false;
var CanOpen : boolean = false;
var NeedKey : boolean = true;
//Audios:
var Locked : AudioClip;
var Open : AudioClip;
//Other:
var Volume : float = 0.5;
var KeyScript : GameObject;
function Start () {
audio.volume = Volume;
}
function Update () {
if(Input.GetKeyUp(KeyCode.E) && !IsOpen && CanOpen && !NeedKey)
{
Opening();
IsOpen = true;
audio.clip = Open;
audio.Play();
}
else if(Input.GetKeyUp(KeyCode.E) && IsOpen && CanOpen && !NeedKey)
{
Closing();
IsOpen = false;
}
else if(Input.GetKeyUp(KeyCode.E) && CanOpen && NeedKey)
{
audio.clip = Locked;
audio.Play();
}
if(KeyScript.GetComponent(Key).HaveKey == true)
{
NeedKey = false;
}
}
function Opening()
{
for (var i = 0; i < 100; i++)
{
transform.Rotate(0,0.9,0);
yield WaitForSeconds(0.01);
}
}
function Closing()
{
for (var i = 0; i < 100; i++)
{
transform.Rotate(0,-0.9,0);
yield WaitForSeconds(0.01);
audio.clip = Open;
audio.Play();
}
}
function OnTriggerEnter (other : Collider)
{
if(other.gameObject.tag == "Player")
{
CanOpen = true;
}
}
function OnTriggerExit (other : Collider)
{
if(other.gameObject.tag == "Player")
{
CanOpen = false;
}
}
@script RequireComponent(AudioSource)
PLEASE HELP IF YOU CAN!
ALSO I FORGOT TO MENTION THAT: BackToNormal and TextureChange Are functions.