Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by HyperNovaGames · Jan 19, 2014 at 07:47 PM · doorskeyslocked

Key script not working right!

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.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nick4 · Jan 19, 2014 at 08:02 PM 0
Share

What's with the unnecessary gaps between lines?

avatar image HyperNovaGames · Jan 19, 2014 at 09:04 PM 0
Share

The unnecessary gaps are to make you see the code and everythng better. (I just chose to.)

avatar image TheShadowblast123 · Jan 19, 2014 at 11:42 PM 0
Share

how is a locked door relevant to a key being picked up?

avatar image HyperNovaGames · Jan 20, 2014 at 12:01 AM 0
Share

The key unlocks the locked door.

avatar image KellyThomas · Jan 20, 2014 at 12:10 AM 0
Share

You have a lot of Boo runtime errors here.

Is your Crosshair script in a file named "Crosshair.js"?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by HyperNovaGames · Jan 22, 2014 at 05:59 PM

I fixxed t just by renaming the cross hair to CrossHair.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image poncho · Jan 22, 2014 at 08:09 PM 0
Share

methods, properties, classes, namespaces, everything is case sensitive

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

looking for help with item pickups 1 Answer

how i can make a gate destroy when the door open ? 1 Answer

Go through door, by loading next scene, with key-press 1 Answer

Correct player position when moving between scenes. 1 Answer

Starting point for leaving each scene? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges