Afin de rendre visible un objet,toutt ce que je sais faire est:
Code : Tout sélectionner
public Material mat;
public Mesh mesh;
public GameObject obj;
obj.AddComponent<MeshRenderer>().material = mat;
obj.AddComponent<MeshFilter>().mesh = mesh;
Changer de materiau(materiau d'une autre couleur)?
ou
un truc du genre ?:
Code : Tout sélectionner
material.color=Color.red;
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class assign_color : MonoBehaviour
{
public GameObject obj1,obj2;
public Material rouge,vert;
public Mesh mesh;
// Start is called before the first frame update
void Start()
{
obj1.AddComponent<MeshRenderer>().material=vert;
obj1.AddComponent<MeshFilter>().mesh = mesh;
obj2.AddComponent<MeshRenderer>().material=rouge;
obj2.AddComponent<MeshFilter>().mesh = mesh;
}
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class assign_color : MonoBehaviour
{
public GameObject obj1,obj2;
public Material[] mats;
public Mesh mesh;
// Start is called before the first frame update
void Start()
{
obj1.AddComponent<MeshRenderer>().sharedMaterial=mats[0];
obj1.AddComponent<MeshFilter>().mesh = mesh;
obj2.AddComponent<MeshRenderer>().sharedMaterial=mats[1];
obj2.AddComponent<MeshFilter>().mesh = mesh;
}
Code : Tout sélectionner
ender.material.SetColor ("_SpecColor", Color.red);
merci de votre aide