<aside> 📄 This script triggers an objects material change when the player collides with it.
</aside>
using UnityEngine;
public class ChangeMaterialOnTrigger : MonoBehaviour
{
// Assign this in the Inspector to the material you want to change to
public Material newMaterial;
// Assign this in the Inspector to the GameObject whose material you want to change
public GameObject targetObject;
private void OnTriggerEnter(Collider other)
{
// Check if the collider is the player (you can also use tags or layers to check)
if (other.CompareTag("Player"))
{
// Get the Renderer component of the target object
Renderer targetRenderer = targetObject.GetComponent<Renderer>();
// If the target object has a Renderer, change its material
if (targetRenderer != null)
{
targetRenderer.material = newMaterial;
}
}
}
}