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 Keylee-P · Oct 26, 2021 at 11:29 PM · scripting problemgame

Door error

Sooooo, I have a script on one of my doors in my game that allows the key im holding to open the door and allow me to move onto the next scene by going through the door. It was working previously after I saved it last week. I made a few more changes to my game for an assignment for school that I did not need in my game, so after I submitted that assignment I clicked "do not save changes." If anyone can help me it would be much appreciated. Also I am very new to scripting :)

Here is the script for the door:

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

public class Door : MonoBehaviour {

 private PlayerAnimController thePlayer;


 public SpriteRenderer theSR;
 public Sprite doorOpenSprite;

 public bool doorOpen, waitingToOpen;


 // Start is called before the first frame update
 void Start()
 {
     thePlayer = FindObjectOfType<PlayerAnimController>();
 }

 // Update is called once per frame
 void Update()
 {
     if (waitingToOpen)
     {
         if (Vector3.Distance(thePlayer.followingKey.transform.position, transform.position) < 0.1f)
         {
             waitingToOpen = false;

             doorOpen = true;

             theSR.sprite = doorOpenSprite;

             thePlayer.followingKey.gameObject.SetActive(false);
             thePlayer.followingKey = null;
         }
     }

     if (doorOpen && Vector3.Distance(thePlayer.transform.position, transform.position) < 1f && Input.GetAxis("Vertical") > 0.5f)
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
     }
 }

 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         if (thePlayer.followingKey != null)
         {
             thePlayer.followingKey.followTarget = transform;
             waitingToOpen = true;
         }
     }
 }

}

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
0

Answer by Xquality · Oct 27, 2021 at 08:19 AM

Could it be that you're not pressing the "w" or "up key" when you're within 1 unit of the open door? Or does the door not open at all?

Comment
Add comment · Show 5 · 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 Keylee-P · Oct 28, 2021 at 02:51 AM 0
Share

The door opens and I am pressing the up key or "w" when im within 1 unit of the door. So it is really odd to me why it is not working.

avatar image Keylee-P · Oct 28, 2021 at 03:14 AM 0
Share

I also have the scenes in proper order In the build settings.

avatar image Xquality · Oct 28, 2021 at 05:15 AM 0
Share

Hm perhaps you could send me the project if it's not too big that is. I'm not sure what's going wrong xd

avatar image Keylee-P Xquality · Oct 28, 2021 at 08:06 PM 0
Share

It is too large to send

avatar image Keylee-P Xquality · Oct 28, 2021 at 09:48 PM 0
Share

Could there possibly be something wrong with my Game Scene Manager. I added a script that my professor told me to add and that works in loading the next screen, however, he said that the "use game scene manager" box should be checked but it only works when it's not checked. While it works in loading the next scene, it does not use the key and open door functions I want it to use. Here is that script for the manager:

public class GameSceneManager : MonoBehaviour { //Like the GameManager, this should be it's own gameobject

 [Tooltip("The black screen transition that will be used")]
 public GameObject Transition;

 [Tooltip("If you want to open this scene with a fade in")]
 public bool startWithFadeIn = true;
 // Start is called before the first frame update
 void Start()
 {
     if (startWithFadeIn)
     {
         StartCoroutine(FadeIn());
     }
 }


 //This function should be called to other scripts so that way you have the transition working
 public void LoadScene(int SceneIndex)
 {
     StartCoroutine(FadeOut());
     StartCoroutine(LoadAsyncScene(SceneIndex));
 }

 IEnumerator LoadAsyncScene(int SceneIndex)
 {
     AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(SceneIndex);

     // Wait until the asynchronous scene fully loads
     while (!asyncLoad.isDone)
     {
         yield return null;
     }
 }

 public IEnumerator FadeIn()
 {
     Transition.SetActive(true);
     Transition.GetComponent<Animator>().SetBool("FadeIn", true);
     yield return new WaitForSeconds(1);
     Transition.GetComponent<Animator>().SetBool("FadeIn", false);
     Transition.SetActive(false);
 }

 public IEnumerator FadeOut()
 {
     Transition.SetActive(true);
     Transition.GetComponent<Animator>().SetBool("FadeOut", true);
     yield return new WaitForSeconds(1);
     Transition.GetComponent<Animator>().SetBool("FadeOut", false);
 }

}

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

255 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity|C#| Card Game: How to draw a card for each 0.5 secs? 2 Answers

Problem TimeScale 4 Answers

C# | How to delay a method with parameters 2 Answers

Is there a way to disable something permanently in a script? 2 Answers

first button click not working,first button click isn't working 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