sample
unknown
plain_text
5 months ago
1.7 kB
2
Indexable
using UnityEngine; using UnityEngine.UI; public class ColorRecognizer : MonoBehaviour { public GameObject redCircle; public GameObject blueSquare; public GameObject yellowTriangle; public Text colorText; private Animator redCircleAnimator; private Animator blueSquareAnimator; private Animator yellowTriangleAnimator; void Start() { redCircleAnimator = redCircle.GetComponent<Animator>(); blueSquareAnimator = blueSquare.GetComponent<Animator>(); yellowTriangleAnimator = yellowTriangle.GetComponent<Animator>(); } void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); Collider2D collider = Physics2D.OverlapPoint(mousePosition); if (collider != null) { GameObject clickedObject = collider.gameObject; if (clickedObject == redCircle) { colorText.text = "Red: Circle"; redCircleAnimator.SetTrigger("PlayAnimation"); } else if (clickedObject == blueSquare) { colorText.text = "Blue: Square"; blueSquareAnimator.SetTrigger("PlayAnimation"); } else if (clickedObject == yellowTriangle) { colorText.text = "Yellow: Triangle"; yellowTriangleAnimator.SetTrigger("PlayAnimation"); } } } } }
Editor is loading...
Leave a Comment