Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by Digitroni · Jan 14, 2018 at 06:36 AM · scene-switchingdoorexitenter

Enter door?

Hello, I'm very new to Unity, and I would like some help with coding. I'm currently making a small 2D side scroller, however I would like the player to be able to enter/exit some buildings. I've attached a photo of what I want exactly to happen. Whenever the player walks in front of a "door" then I want an image to appear (which says press the up arrow to enter), and then upon pressing the button the person enters. How would I go about doing this? Please keep in mind that I'm new and have next to no experience with coding. Using C#.

https://imgur.com/a/xhr7o

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 PersianKiller · Jan 14, 2018 at 09:38 AM

hi,watch this nice and simple tutorial it will help you.it's very easy :).

part1

https://streamable.com/a8xy5

part2

https://streamable.com/xzuhe

if you needed more help ,leave a comment I will help if I could.

Comment
Add comment · Show 6 · 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 Digitroni · Jan 14, 2018 at 07:46 PM 0
Share

Hey, so I did it and it works well. However, whenever I transition to "inside the house" the box colliders of the outside world are still present, so if there was a wall in the outside world, whenever the player transitioned inside the house, the 2D box collider would still be in the way. Any help for this? Thanks!

avatar image Digitroni · Jan 14, 2018 at 07:48 PM 0
Share

heres the code

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class door : $$anonymous$$onoBehaviour { public GameObject $$anonymous$$art; public GameObject pressButtonImage; public GameObject insideTheHome; public int InsideTheHome;

 //
 void OnTriggerEnter2D(Collider2D other) {
     if (other.CompareTag ("Player")) {
         pressButtonImage.SetActive (true);
     }
 }

 void OnTriggerStay2D(Collider2D other){
     if (other.CompareTag ("Player") && Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.UpArrow)) {

         Debug.Log ("$$anonymous$$eyPressed");

         if (InsideTheHome == 0) {

             insideTheHome.SetActive (true);
             $$anonymous$$art.GetComponent<SpriteRenderer> ().enabled = false;
             InsideTheHome = 1;
         } else if (InsideTheHome == 1) {
             insideTheHome.SetActive (false);
             $$anonymous$$art.GetComponent<SpriteRenderer> ().enabled = true;
             InsideTheHome = 0;

         }
     }
 }

 void OnTriggerExit2D(Collider2D other) {
     if (other.CompareTag ("Player")) {
         pressButtonImage.SetActive (false);
     }
 }

}

avatar image PersianKiller Digitroni · Jan 15, 2018 at 03:13 AM 0
Share

because it was just an example, simply you can create some GameObjcets for example next House.when you pressUparrow$$anonymous$$ey nextHouse should be disable,so you can't collide with them watch it :)

https://streamable.com/hp1o5

edit : my bad I forgot to make playerCanGoInsideTheHouse false when the player is not standing near the door change it to this.

           void OnTriggerExit2D(Collider2D other){ 
     if (other.CompareTag ("player")) {
         pressButtonImage.SetActive (false);
         playerCanGoInsideTheHouse = false;//so you cannot press the button
          
     }

 }
avatar image Digitroni PersianKiller · Jan 16, 2018 at 02:59 PM 0
Share

What? I'm confused at this response, sorry.

Show more comments

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

125 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 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 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 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 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 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

How to make an enter building button in a 2D game? 0 Answers

Help with Enter/Exit modified for a turret or cannon in C# 1 Answer

Whats wrong in my code or logic, please help!,Hi everyone, i have a problem with a door key situation: 1 Answer

Enter and exit with animations 2 Answers

Open Door Animation Problem 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