у меня есть вопрос, как сделать чтобы текст в юнити, точнее символы, меняли свой цвет при контакте с объектом шар? если есть пример кода как можно сделать, или видео, то был бы очень рад, когда сам писал код, то не разобрался в колайдере, прикреплял колайдер к шарику и тексту, использовал text legacy , на шарике ставил галочку Triger.
using UnityEngine;
using UnityEngine.UI;
public class StringCharacter : MonoBehaviour
{
public Color changeColor; // Цвет, на который будет изменяться символ при касании
private Text textComponent;
private Color originalColor;
private bool isTouched = false; // Флаг, указывающий, касается ли шар символа
void Start()
{
textComponent = GetComponent<Text>();
if (textComponent == null)
{
Debug.LogError("Text component not found on this GameObject. Make sure it's attached to the same GameObject.");
return;
}
originalColor = textComponent.color;
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Ball") && !isTouched)
{
textComponent.color = changeColor;
isTouched = true; // Устанавливаем флаг, чтобы символ был касаемым
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Ball"))
{
textComponent.color = originalColor;
isTouched = false; // Сбрасываем флаг, когда шар покидает символ
}
}
}
Qwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.