using UnityEngine; using UnityEngine.UI; public class ChangeImageSprite : MonoBehaviour { public Sprite newSprite; private Image imageComponent; private void Start() { // Get reference to the Image component on this GameObject imageComponent = GetComponent(); } private void Update() { // Change the sprite being displayed by the Image component imageComponent.sprite = newSprite; } }
using UnityEngine; using UnityEngine.UI; public class ChangeImageColor : MonoBehaviour { public Color newColor; private Image imageComponent; private void Start() { // Get reference to the Image component on this GameObject imageComponent = GetComponent(); } private void Update() { // Change the color of the Image component imageComponent.color = newColor; } }This script changes the color of an Image component to a new color that's defined as a public variable on the component. The Start() method gets a reference to the Image component on the same GameObject as this script, and the Update() method constantly updates the color of the Image component to the newColor color. Package Library: The UnityEngine.UI Image component is part of the Unity engine's UI system, which is included in the "UnityEngine.UI" package.