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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by superdave1318 · Jul 31, 2014 at 04:45 PM · noob

Click Meh! Open door/close when clicked.

Im a scripting noob so please go easy on me..

Ive spent a decent 10 minutes looking how to do this but all the other answers are for dragging the door open, i just want it that when clicked, the door will will open and close from its hinge at about 85 degrees. Like ive shown below. Can anyone guide me through what i need to do? Before:

Before

After:

after

marko1.jpg (43.2 kB)
marko2.jpg (42.6 kB)
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 $$anonymous$$ · Jul 31, 2014 at 04:52 PM 0
Share

One way is to add a ColliderComponent + Animation + script to the door GameObject (C#):

 On$$anonymous$$ouseOver()
 {
    if(Input.$$anonymous$$ouseButtonUp(0))
    {
       this.animation.Play("YourDoorAnimation");
    }
 }

2 Replies

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

Answer by SterlingStudios · Jul 31, 2014 at 04:50 PM

Make an animation for it, it's relatively simple. Here is some code:

 var animationName : AnimationClip;
 var isOpen : boolean;
 var inTrigger : boolean;
 var inSight : boolean;

 function Update () {
 
     if(Input.GetMouseButtonDown(0) && inTrigger == true && inSight == true) {
        isOpen =! isOpen;
     }
 
     if(isOpen == true)
        animation[animationName.name].speed = 1;
        animation.Play(animationName.name);
     
     else if(isOpen == false)
        animation[animationName.name].speed = -1;
        animation.Play(animationName.name);
 }

  function OnMouseEnter () {

 inSight = true;
 }

 function OnMouseExit () {

 inSight = false;
 }

 function OnTriggerEnter (col : Collider) {

    if(col.gameObject.tag == "Player") {
        inTrigger = true;
 }

}

WARNING: Un-tested code

Edit: Made it so you have to be in the trigger and have the mouse over it. STILL UN-TESTED.

Comment
Add comment · Show 7 · 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 superdave1318 · Jul 31, 2014 at 04:56 PM 0
Share

Will using an animation work the same as otherwise? (As in, i wont be able to walk through it n' stuff?

avatar image SterlingStudios · Jul 31, 2014 at 04:59 PM 0
Share

As long as you attach a collider, it should be fine.

avatar image superdave1318 · Jul 31, 2014 at 05:05 PM 0
Share

Perfect, now all i got to do is learn how to animate. Which, i have no idea to do XD. 2 steps forward, 2 steps back, thnx for your help so far!

avatar image SterlingStudios · Jul 31, 2014 at 05:06 PM 0
Share

Don't worry it's really easy :D. Just make sure to add the curve before you start and then make it go to 85 degrees.

avatar image superdave1318 · Jul 31, 2014 at 05:21 PM 0
Share

Whats a curve?

Show more comments
avatar image
0

Answer by NoName115 · Aug 01, 2014 at 12:00 AM

I think that good choise is rotating the object, if you have a pivot on the one side of that door, you simple could use this gameObject.transform.rotate(new Vector3(0, 0, 85));

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 superdave1318 · Aug 01, 2014 at 03:09 PM 0
Share

Yes but how do i implement gameObject.transform.rotate(new Vector3(0, 0, 85)); into my script? (Like i said, im a noob, i dont know where to put it)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Enter Trigger, display Text, then delete object 1 Answer

(NOOB Q) Whats wrong with my script? Two if's? 3 Answers

What is wrong with my RockPaperSissors script? 1 Answer

Unknown Identifiers for declared variables? 2 Answers

Only access door if it's not locked? 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