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 martocapo · Nov 27, 2020 at 05:36 PM · raycastsorting order

sortingLayer not working in almost all the scenes

Hello Guys,

I am new in the forum and almost new in unity. I currently having a issue with changin the sortinglayer of a door when i click on. The main purpuse to change the order to back and show sprite with a open Door. The script i made works great in one of the scenes but its not working in other two. I am using the new input method for the mouse clicking, so when i click on an object with a 2d collider it will be detected by the ray i create and show a message like "hit door" and change the order hidden the closed door sprite and showing the open door sprite. This method works in the main scene but it does not in other with the same structure. In the other scenes is only showing the message in the console. Here is the clickdoor script:

 public class ClickDoor : MonoBehaviour
 {
     float Order;
     public void Update()
     {
     
     }
     public void OnClickDoor()
     {
         Order = gameObject.GetComponent<SpriteRenderer>().sortingOrder;
         //if (gameObject.activeSelf == true)
         //if (gameObject.GetComponent<SpriteRenderer>().sortingOrder == 1)
         if (Order == 1)
         {
             gameObject.GetComponent<SpriteRenderer>().sortingOrder = -3;
             //gameObject.SetActive(false);
         }
         if (Order == -3)
         {
             gameObject.GetComponent<SpriteRenderer>().sortingOrder = 1;
             //gameObject.SetActive(true);
         }
         //Debug.Log("Hit Door");
      }

And here is the part of the function from cursorcontrol script:

 private void DetectObject()
     {
         Ray ray = mainCamera.ScreenPointToRay(controls.Mouse.Position.ReadValue<Vector2>());
 
         //    RaycastHit2D hits2D = Physics2D.GetRayIntersection(ray);
         //    if (hits2D.collider != null)
         //    {
         //   if (hits2D.collider.tag == "Door")
         //   {
         //   Debug.Log("2D Hit:" + hits2D.collider.tag);
         //gameObject.SetActive(false);
         //hits2D.collider.gameObject.GetComponent<ClickDoor>().OnClickDoor();
         //} else
         //{
         //    gameObject.SetActive(true);
         //}
         //}
         //}
         RaycastHit2D[] hits2DAll = Physics2D.GetRayIntersectionAll(ray);
         for (int i = 0; i < hits2DAll.Length; ++i)
         {
             if (hits2DAll[i].collider != null)
             {
                 if (hits2DAll[i].collider.name == "Door")
                 {
                     //Debug.Log("Hit Door");
                     hits2DAll[i].collider.gameObject.GetComponent<ClickDoor>().OnClickDoor();
                 }
                 if (hits2DAll[i].collider.name == "DoorOpen")
                 {
                     //Debug.Log("Hit DoorOpen");
                     hits2DAll[i].collider.gameObject.GetComponent<ClickDoorScummBar>().OnClickDoorScummBar();
                 }
                 if (hits2DAll[i].collider.name == "Kitchen_Pier_Door_Open")
                 {
                     //Debug.Log("Hit DoorOpen");
                     hits2DAll[i].collider.gameObject.GetComponent<ClickDoorKitchen>().OnClickDoorKitchen();
                 }
                 
                 // Debug.Log("2D Hit All:" + hits2DAll[i].collider.tag);
             }
         }
     }

Please if have time to take a look and help me i will be really appreciate it. Thanks you a lot in advance Best Regards

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

0 Replies

· Add your reply
  • Sort: 

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

194 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

Related Questions

Prevent Raycast on reacting to GUI input? 2 Answers

Noob Raycast question 0 Answers

Confused as to how my RaycastHit script works 1 Answer

How to make a laser beam effect with raycast? 1 Answer

Raycast and Layer Masks 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