Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
0
Question by HoneyBadgerDigital · Aug 13, 2021 at 08:56 AM · 3dmaterialarray of gameobjectsmaterial colormaterial renderer

Material Instance doesn’t work correctly (involve Array)

-What I want to do (goal): I want to hide the wall when the player enter a room, hide all things on top of that room (like 2nd floor) -How I approached it: reduce the alpha of the 1st floor and disable renderer of the 2nd floor (&EverythingOnThere) by: + Create a Bool isInRoomB to check wether the character is in a room or not (using RayCast):

  private bool checkRoof(Vector3 Origin)
 {
     Origin += Vector3.up * 3;
     RaycastHit hit;
     Ray checkRoofRay = new Ray(Origin, Vector3.up);
     Debug.DrawRay(checkRoofRay.origin, checkRoofRay.direction * 10, Color.red);

 if (Physics.Raycast(checkRoofRay, out hit))
 {
     currentRoof = hit.transform.gameObject;
     if (hit.collider.tag == "Roof")
     {
         Debug.DrawRay(checkRoofRay.origin, checkRoofRay.direction * 90, Color.grey);
         return true;
     }
 }
 return false;

}

  • I create an array to store the material when the player first go to the room, When the character enter, “isInRoomB” is set to “true” and the Renderer of the Ceiling get all of it’s parent’s renderer. (the 2ndFloor and Everything on there) then hide the 2nd floor and make the 1st transparent

  • The Format of this code just doesnt work correctly on here, pls look over it.

    private void ChangeTransparent(bool isInRoomB, GameObject currentRoof) { Debug.Log("inRoomB = " + inRoomB); if (isInRoomB) { GameObject currentWall = currentRoof.transform.parent.gameObject; renArr = currentWall.GetComponentsInParent();

            for (int i = 0; i < renArr.Length; i++)
              {
                  if (i == 0) 
                  {
                      m_objectColor.a = seeThroughRate;
                      renArr[i].material.color = m_objectColor;
                  }//invisible current floor and 
                  else 
                  {
                      renArr[i].enabled = false;
                  }//disable those that's on top
              }
          }
          else
          {
              for (int i = 0; i < renArr.Length; i++)
              {
                  m_objectColor.a = 1.0f;
                  renArr[i].material.color = m_objectColor;
                  m_ObjectRenderer = renArr[i];
                  renArr[i].enabled = true;
              }
          }
      }
    
    
  • When the character isn’t in that room anymore, the RendererArray is still the same bc the ray hasn’t contact with another ceiling yet. It then return the alpha to 1.0f to not make it transparent anymore and enable the renderer of the 2nd floor & everything on it

  • The problem: when character exits the room, everything should change to normal like before. However every materials has been altered to be the instance material that looks like the outer wall. I have no Idea why. Thanks in advance. Below is the img:alt text

  • *For someone who're thinking about “renderer[i].material = normal & transparent” It doesn’t work. I tried it: by switching Material (using 2 arrays to store and switching material) & it just has the same problem

question.jpg (101.5 kB)
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

172 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

Related Questions

Material cant be seen until Im very close 1 Answer

Disable 1 of the 2 Materials from the same Object. 1 Answer

How to check if two objects share the same material within an if statement? 0 Answers

Shared materials over muliple players 2 Answers

Emissive Material control via script (code) 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