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 rbatelaan2 · Jan 14, 2021 at 05:58 PM · transparencydictionaryrenderer.enabled

How can I change the transparency of gameobjects with a dictionary?

I am trying to change the transparency of gameobjects based on their position using a dictionary. I am getting the correct float transparency value, but the actual transparency is not changing. Also, the renderer is not turning off for the gameobjects that have a transparency less than or equal to zero. In the inspector, I have set the Renderer Rend to Mesh Renderer of that gameobject. Here is my script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Valve.VR;
 
 public class AssignTransparency : MonoBehaviour
 {
     public GameObject obj;
     public Renderer rend;
     public Color color;
     public float transparency;
     public myDictionary m_Dictionary;
     public SteamVR_Action_Boolean Trigger;
 
     // Start is called before the first frame update
     void Start()
     {
         rend = GetComponent<Renderer>();
         rend.enabled = false;
         color = this.GetComponent<MeshRenderer>().material.color;
         m_Dictionary = obj.GetComponent<myDictionary>();
         transparency = myDictionary.data[transform.position];
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Trigger.state && transparency > 0)
         {
             rend.enabled = true;
             color.a = transparency;
         }
     }
 }
 
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
Best Answer

Answer by CmdrZin · Jan 14, 2021 at 06:22 PM

Move these two lines to the beginning of your Update method.

          rend.enabled = false;
          transparency = myDictionary.data[transform.position];

else once your rend.enabled is set to true, it never goes false and your transparency per distance never updates.

Comment
Add comment · Show 2 · 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 rbatelaan2 · Jan 14, 2021 at 08:33 PM 0
Share

That did not work. Also, my gameobject is not moving so I shouldn't have to update the transparency value. I have multiple clones of a prefab with this script instantiated at start at different positions. In the inspector, the transparency value is correct and the public color in the script is set to the correct transparency, but the actual transparency of the object doesn't change. Also, the renderer is turned off for all of the gameobjects, even when the transparency value is greater than zero.

avatar image CmdrZin · Jan 14, 2021 at 08:42 PM 0
Share

because you are not changing the object's color. You're only changing the copy of it in a Color variable. Use

 this.GetComponent<$$anonymous$$eshRenderer>().material.color.a = transparency;

or make a $$anonymous$$eshRanderer variable to have a reference to the object.

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

111 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

Related Questions

Unity making existing shader partially transparent 1 Answer

How to sort draw order on transparent character puppet. 0 Answers

Object transparency separate from shader? 0 Answers

Help understanding transparency in Deferred Rendering? 0 Answers

Standard shader - fade mode renders texture in wrong order 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