J'ai l'habitude de réaliser des scripts manipulant des objets dotés d'un seul matériau:
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class myScript: MonoBehaviour {
public GameObject myObject_with_unique_material;
public Mesh meshObject;
public Material noir;
void Start () {
myObject_with_unique_material.AddComponent<MeshRenderer>().material = noir;;
}
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class myScript2: MonoBehaviour {
public GameObject myObject_with_two_materials;
public Mesh meshObject;
public Material blanc,noir;
void Start () {
myObject_with_two_materials.AddComponent<MeshRenderer>().material[0] = blanc; //1
myObject_with_two_materials.AddComponent<MeshRenderer>().material[1] = noir; //2
}
}
1)De quelle manière dans myScript2 je déclare un tableau de matériaux comportant 2 éléments de façon à ce que les lignes 1 et 2 du script fonctionnent?
2)même question si je décide de rentrer et choisir le nombre de matériaux(sérialisation)
merci de votre aide