Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Nicholi · Jan 11, 2011 at 06:15 AM · errordoor

Scripting woes, door will not open

How can I get this to work, every time I plug in the designated script for the door to open that is detailed in the unity essentials book it then has supposed "unknown identifiers- doorIsOpen etc" galore even though the people using it have all said the contrary that it supposedly always works...

function OnControllerColliderHit (hit : ControllerColliderHit) { if (hit.gameObject.tag == "outpostDoor" && doorIsOpen == false) { currentDoor = hit.gameObject; Door(doorOpenSound, true, "dooropen", currentDoor); }

 var hit : RaycastHit;

 if(Physics.Raycast(transform.position, transform.forward, hit, 5)) 
 {  
     if(hit.collider.gameObject.tag == "outpostDoor" && doorIsOpen == false)
     {
         currentDoor = hit.collider.gameObject;
         Door(doorOpenSound, true, "dooropen", currentDoor);

Please help.

Comment
Add comment · Show 1
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 Justin Warner · Jan 11, 2011 at 03:20 PM 2
Share

For future, please, don't say "hell" AND format your code, as I'm skipping the question because I can't even read it...

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Statement · Jan 11, 2011 at 06:06 PM

I won't be bothered reading the whole article, but I can provide my own implementation for opening/closing doors.

First is the script for the door. It is quite minimal. OnInteract is what the door will do when a user interacts with it. Here you might want to add more features such as playing a sound with audio.Play() for example. You can make all sorts of scripts that have OnInteract, with this approach. Maybe you want to make a button? Maybe you want to make a car you can enter. All of this can make use of this basic skeleton.

// Door.js var isOpen : boolean;

function OnInteract() { var anim = isOpen ? "CloseDoor" : "OpenDoor"; animation.Play(anim); isOpen = !isOpen; }

Then is the script for the player, that interact with the door. I chose to query the main camera to avoid restrictions that you must put it on a camera and for ease of use. range variable is how far the player can reach. blockingLayers are which objects block a raytest. This can be useful if you have certain triggers that would block the ray.

// Interacter.js var range : float = 5; var blockingLayers : LayerMask = -1;

function Update() { if (Input.GetKeyDown(KeyCode.E)) Interact(); }

function Interact() { var hit : RaycastHit; var ray : Ray = Camera.main.ViewportPointToRay(Vector3(0.5, 0.5, 0)); var options = SendMessageOptions.DontRequireReceiver;

 if (Physics.Raycast(ray, hit, range, blockingLayers))
     hit.collider.SendMessage("OnInteract", options);

}

It is quite minimalistic and I hope you have a better chance learning scripting this way. Free code is frowned upon, but I also realize when you are struggling the most and want to come to a quick resolution to keep the spirits high. I provide this code free to you this time, but don't expect to always be lucky! :)

Comment
Add comment · Show 11 · 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 Nicholi · Jan 11, 2011 at 06:40 PM 0
Share

I hate to break it to you but this will not work in my fps script:

Assets/Standard Assets/Character Controllers/Sources/Scripts/FPSInputController.js(30,10): BCE0044: expecting (, found 'Update'.

Assets/Standard Assets/Character Controllers/Sources/Scripts/FPSInputController.js(30,10): BCE0044: expecting (, found ''.

avatar image Nicholi · Jan 11, 2011 at 07:02 PM 0
Share

$$anonymous$$issingComponentException: There is no 'Animation' attached to the "door" game object, but a script is trying to access it. You probably need to add a Animation to the game object "door". Or your script needs to check if the component is attached before using it. UnityEngine.Animation.Play (System.String animation) (at E:/BuildAgent/work/71ca6fec1b41cc30/Runtime/Export/Generated/Animations.cs:393) Door mech.OnInteract () (at Assets/Door mech.js:9)

avatar image Statement · Jan 11, 2011 at 07:10 PM 0
Share

I have no idea what you did wrong in your first comment. The code works fine on my machine. $$anonymous$$aybe you pasted it wrong. I think the last error messages said just what I will tell you too. This all require that you have an animation component on the door. Read the errors, they aren't that hard to read. Sure, there is some strange numbers but most errors provide useful information.

avatar image Statement · Jan 11, 2011 at 07:13 PM 0
Share

The code I presented are supposed to go into new code files. This is complete code. It doesn't have to merge with anything old.

avatar image Nicholi · Jan 11, 2011 at 07:27 PM 0
Share

"This all require that you have an animation component on the door." Then why did you leave it out if its part of the function? Also its not like I haven't read it it clearly states that some animation component is left out of the function ;)

Show more comments
avatar image
1

Answer by Zylar · Jan 11, 2011 at 08:01 AM

Check where it is you declared the variable doorIsOpen. If it is inside of a function, then that means it'll only be known inside of that function. Your OnControllerColliderHit function can't find it because some other function is stealing all of doorIsOpen's attention.

Don't declare it inside of a function if you want more than one function to talk to it.

Comment
Add comment · 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
0

Answer by Nicholi · Jan 11, 2011 at 05:30 PM

No, you misunderstood, I have tired that and every other possible valid series of scripts for this I could find on this site and it still doesn't work and the book clearly states that you are suppose to set these functions inside /* then supposedly it will work..

Could you or anyone bestow to me a formatted script that will work. I tried both methods in this book and neither work for me.

Fyi the ones found here : http://www.packtpub.com/article/unity-game-development-interactions-part2

Comment
Add comment · Show 4 · 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 Statement · Jan 11, 2011 at 05:37 PM 0
Share

Well, I formatted YOUR script. It isn't even a complete function.

avatar image Nicholi · Jan 11, 2011 at 06:38 PM 0
Share

So how exactly is it my script and not even a complete function if its whats published in the unity essentials book?

avatar image Statement · Jan 11, 2011 at 07:12 PM 0
Share

Well you posted it. You are using it. Hence I call it yours. I can't check every book for reference. All I know, the code posted didn't work and formatting that code (so it was even readable) revealed that the function wasn't complete. I doubt the book would offer broken scripts, but maybe they presented it in fragments that were hard to put together?

avatar image Nicholi · Jan 11, 2011 at 07:25 PM 0
Share

Wrong the book states that its a complete function, it doesn't work for me for whatever reason probably has to do with placement issues as the book is a bit vague with its "few lines down from Update()" instructions

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Weird collision error when using waypoint script... 1 Answer

Getting index of the smallest number in a list 1 Answer

NullReferenceException problem 2 Answers

BCE0049 error with networking script 0 Answers


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