I'm currently working on a Unity project that involves Vuforia, and I've encountered a challenge regarding a button that's supposed to make a 3D object transparent when clicked. Unfortunately, the script I've implemented isn't producing the expected results. Here's the situation and the code I've used:
I have a button within my scene, and I'm aiming to utilize it to trigger the transparency effect on a 3D object. Here's the script I've developed for this purpose:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ToggleTransparency : MonoBehaviour
{
public GameObject carModel;
private Material carMaterial;
private bool isTransparent = false;
private void Start()
{
carMaterial = carModel.GetComponent<Renderer>().material;
}
public void ToggleCarTransparency()
{
isTransparent = !isTransparent;
Color materialColor = carMaterial.color;
if (isTransparent)
{
materialColor.a = 0.5f;
}
else
{
materialColor.a = 1f;
}
carMaterial.color = materialColor;
}
}
I've attached this script to my button GameObject. However, despite my efforts, clicking the button does not change the object's transparency level. Considering that Vuforia is involved, I'm wondering if there might be some interaction with its features that's causing the issue. If anyone has experience working with both Unity and Vuforia and can offer insights into what might be causing the problem, I would greatly appreciate your guidance.
Thank you for your time!