Hi, im making a gameobject that can be outlined when clicked, but filter the way im filtering out the outline material(via name(i checked and the name matches with the material i want to remove)) is not working and i need help, thanks.
using System.Collections;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.Assertions.Must;
using UnityEngine.Rendering;
using UnityEngine.UI;
using UnityEngine.UIElements;
public class Click : MonoBehaviour
{
public GameObject[] highlightable;
void Start()
{
if (GameObject.FindGameObjectsWithTag("Clickable Object") != null)
{
highlightable = GameObject.FindGameObjectsWithTag("Clickable Object");
}
Unclicked();
}
void Update()
{
}
void Unclicked()
{
foreach (GameObject gameObject in highlightable)
{
Material[] tempMats;
tempMats = gameObject.GetComponent<MeshRenderer>().materials;
for (int i=0;i == tempMats.Length;i++)
{
if (tempMats[i].name == "Outline Material")
{
tempMats[i] = null;
}
}
gameObject.GetComponent<MeshRenderer>().SetMaterials(materials: tempMats.ToList());
}
}
}
It mostly worked, but unity replaced the new mat texture withe the no texture texture, thanks ,btw
– Trussmister"It mostly worked, but unity replaced the new mat texture withe the no texture texture". I have no clue what this means. What new mat?
– ArachnidAnimalthe other material in the game object, i looked at the mesh renderer and confirmed that it applied it, but it just didnt render
– TrussmisterIt applied what? Your code is only setting a material slot to null, which means no material.
– ArachnidAnimalYea, but it also broke the material i wanted to keep and didnt set to null
– Trussmister