rendre transparent un objet
Publié : 22 Déc 2021 21:39
bonjour,
Ce petit script uarait pour but de rendre transparent un objet qui avait auparavant un matériau.
Ce script, ne fonctionne pas.Pourquoi?
Ce petit script uarait pour but de rendre transparent un objet qui avait auparavant un matériau.
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class transp : MonoBehaviour
{
public Material mat;
public Mesh mesh;
public GameObject obj;
Material mat1,mat2;
float alphaValue;
// Start is called before the first frame update
void Start()
{
obj.AddComponent<MeshRenderer>().material=ChangeAlpha(mat,0);
}
Material ChangeAlpha(Material mat1, float alphaValue)
{
Color oldColor = mat.color;
Color newColor = new Color(oldColor.r, oldColor.g, oldColor.b, alphaValue);
mat.SetColor("_Color", newColor);
return mat2;
}
}