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();
rend.enabled = false;
color = this.GetComponent().material.color;
m_Dictionary = obj.GetComponent();
transparency = myDictionary.data[transform.position];
}
// Update is called once per frame
void Update()
{
if (Trigger.state && transparency > 0)
{
rend.enabled = true;
color.a = transparency;
}
}
}
↧