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 TheTwistedScribbler · Mar 01, 2015 at 04:17 PM · 2d-platformerscenesdoors

Doors and Multiple Scenes - 2D

I'm making a 2D PixelArt Survival-Horror/Platformer, and I just got death and respawning to work, but: http://i.imgur.com/vLFh2j1.png

How do I add this:? I want to make it so when you're in proximity of the door, you press E and then an animation plays when the door opens and then it fades to black and fades back and you're in next scene.

It sounds simple probably like:

 play animation ("Door_Open")
 
 fade to black
 
 load scene ("Scene_02")
 
 fade back

Please, clarify what I have to write, please. Thanks!

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
1

Answer by sparkzbarca · Mar 01, 2015 at 04:45 PM

so it depends on what you want it to look like, yes your right

create a new animation called door open, make it then do doorOpen.play() to open the door.

actually for this simple a thing you dont have to use animations persay. animation is just code after all. you can actually just write out the code to open the door.

a door opens along it's y axis edge normally 90 degrees.

create a "door" or rectangle just for testing purposes.

add a script that basically says this.

//while close enough, there are a lot of ways to do this the easiest is a distance check

 if (vector3.Distance(player.transform.position, door.transform.position) < MaxDistance && input.getbuttondown "Action Key")

//you'll notice i use getbuttondown, not getkey or getkeydown or getbutton. //thats because you shouldn't use getkey, it prevents you from easily redefining the input, //you don't use getbutton or getkey because the door would open multiple times unless the player //clicked REALLY REALLY fast, get key/button is for holding stuff down, get x down is for //whenever a player should only click a key not ever hold it down. //if you want E to be the default key for action key or whatever you want to name it. //go into unity, edit->project settings-> input, thats the list of buttons and names and such //add a new input by changing size or take over an existing one and make it so the name is //action key or whatever you wish to call it and the positive button is e {

//now we rotate the door, first we find the doors edge, thats simply from the middle of the door to one half the width of the door. You could also create an empty game object placed on an edge and rotatearound that. one half an objects size is so common its built in, its called its extents.

 vector3 point = door.transform.position + new vector3(door.collider.bounds.extents.x,0,0);

//this is a point on an edge, hopefully you can see how that works, we take the doors position /and move along the x axis half the width of the door, if we'd like to get the opposite edge //we - instead of + the value.

//rotatearound takes a point, an axis, an angle //our point is what we just found, our axis is the Y axis, up and down because thats the axis //doors rotate around, our angle is 90 because a door opens 90 degrees.

 door.transform.RotateAround(point,door.transform.up,90);

//except this opens the door instantly, you can lerp to rotate slowly by changing that 90 to //a variable like time.deltatime and that will rotate it a small amount each frame, then you want //to just check the angle and if its over 90 stop.

//alot of explanation here but its like 4 lines of code, i just want to make sure you understand //what your doing and aren't just regurgitating my code.

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 TheTwistedScribbler · Mar 01, 2015 at 10:06 PM 0
Share

Okay, I'll try that. I'll tell you if I get any errors.

avatar image TheTwistedScribbler · Mar 02, 2015 at 12:14 AM 0
Share

Alright, so I'm about to test it. It probably won't work cause I suck at coding, but here's what I got (BTW, I am trying to learn, so I read like everything you wrote twice)...

 #pragma strict
 
 function Start () {
 
 }
 
 function Update () {
 if (vector3.Distance(player.transform.position, door.transform.position) < $$anonymous$$axDistance & input.getbuttondown ("Action"));
     {
         vector3 point = door.transform.position + new vector3(door.collider.bounds.extents.x,0,0);
          door.transform.RotateAround(point,door.transform.up,90);
      }
 }

Alright, so, I limited the errors I'm getting down to 1, and it's saying that on line 10, it's expecting a semicolon at the end, but I can see one there. xD

avatar image TheTwistedScribbler · Mar 02, 2015 at 12:14 AM 0
Share

Tell me whether or not that's right, meanwhile, I'll test it.

avatar image TheTwistedScribbler · Mar 02, 2015 at 03:02 AM 0
Share

BTW, where do I add the scene change in all this?

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

Remembering Previously Loaded Scenes "Doors" 1 Answer

Help. Newbie trying to have more than one button powered door a scene 1 Answer

Splitscreen, players in differnt scenes 0 Answers

Calling a command in specific scenes 1 Answer

SceneManager.Load is not worked in subfolders 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