Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Kag359six · Jul 04, 2011 at 11:40 PM · buttontriggerontriggerenter

triggering a door to open with a button

im trying to figure out how to trigger my hoist door to open with the space bar. however i only want to be able to open the hoist door when im in the trigger box that i made. the script im using gives no errors but it still doesnt work. heres the script:

 var doorUp : AnimationClip;
 
 
 function OnTriggerEnter (mytrigger : Collider) {
 
 if(mytrigger.gameObject.name == "player" )
 {
     
     if(Input.GetButton("openDoor"))
 {
         door = gameObject.Find("door");
         door.animation.Play("hoistDoorUp");
     }
     
     
 }
 }
Comment
Add comment
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

1 Reply

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

Answer by Chris D · Jul 05, 2011 at 12:01 AM

The first thing that pops out at me is that you're using OnTriggerEnter and not OnTriggerStay.

The former will only fire for the frame it occurs on (better be holding down the openDoor key) whereas the latter will check for the keypress as long as you're in the trigger area.

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 Kag359six · Jul 05, 2011 at 05:24 PM 0
Share

excellent thanks very much thats exactly what I needed!

avatar image Kag359six · Jul 05, 2011 at 05:28 PM 0
Share

and i have another question...i have a player with a character controller, but i need to make sure that some sort of gravity like system is applied to it. heres the script for my player. what should i add to apply gravity? script:

 private var controller : CharacterController;
 var speed : float = 4f;
 public var woman : Transform;
 
 
 function Start ()
 {
     controller = GetComponent(CharacterController);
     
 }
     
 function Update () {
 
 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0,
                                Input.GetAxis("Vertical"));
 moveDirection = woman.TransformDirection(moveDirection);
 moveDirection *= speed;
 controller.$$anonymous$$ove(moveDirection * Time.deltaTime);      
 }
 
 
 
 
 @script RequireComponent(CharacterController)
avatar image Chris D · Jul 05, 2011 at 05:37 PM 0
Share

Two things:

  1. If you're going to post code, please make sure it's formatted correctly (if you're posting to the comments section, it's easier to compose everything properly in the Answer box, then copy/paste over because formatting is a pain)

  2. Don't post new questions in an older question. Take a $$anonymous$$ute to search through older questions (search box in the top right) and, if you can't find something that helps, open a new one. This question has been answered and the answer has been accepted so most people won't give it a second glance.

avatar image Kag359six · Jul 05, 2011 at 05:45 PM 0
Share

alright thanks

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

OnTriggerEnter gives me error? 2 Answers

Disable Mesh Collider Trigger 1 Answer

OnTriggerEnter fails to activate 1 Answer

Button back not clickable after rotation animation 1 Answer

Activating One Part of An Animation 2 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