- Home /
How do you change text after highlighting a specific image via script?
Hello. I'm currently working on a digital board game and I'm trying to create a system where passing by the GO Space would cause text in the P1 card to change (for the purposes of what I'm working on, I'm simulating a number increasing rather than implementing an actual counter). This is the Game Manager I'm using at the moment:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class GameManager : MonoBehaviour {
     public List<Image> spaceList;
     public int P1Position;
     public int P2Position;
     public int P1Goal;
     public int P2Goal;
     public static GameManager Instance;
     public SpaceQueue P1Queue;
     public SpaceQueue P2Queue;
     public Image GetSpace(int index)
     {
         return spaceList[index % spaceList.Count];
     }
     // Use this for initialization
     void Start ()
     {
         if (GameManager.Instance == null)
         {
             GameManager.Instance = this;
         }
     }
     public void TakeTurnP1()
     {
         int P1Movement = 6;
         P1Goal = P1Position + P1Movement;
         P1Queue.Move(P1Position, P1Goal);
         P1Position = P1Goal;
     }
     public void TakeTurnP2()
     {
         int P2Movement = 3;
         P2Goal = P2Position + P2Movement;
         P2Queue.Move(P2Position, P2Goal);
         P2Position = P2Goal;
     }
     // Update is called once per frame
     void Update () {
         
     }
 }
And here is the queue I'm using called Space Queue:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class SpaceQueue : MonoBehaviour {
     public Color color;
     public Queue<Image> Spaces;
     public Image currentSpace;
     public List<Image> testList;
     public bool P1;
     public int Goal;
     void Start () {
         Spaces = new Queue<Image>();
     }
     public void Move(int from, int to)
     {
         Goal = to;
         for (int i = from; i <= to; i++)
         {
             Spaces.Enqueue(GameManager.Instance.GetSpace(i));
         }
         LightSpaces();
     }
     void LightSpaces()
     {
         StartCoroutine(LightNextSpace());
     }
 
     IEnumerator LightNextSpace()
     {
         if (currentSpace != null)
         {
             // turn off the current space
             currentSpace.color = Color.white;
         }
         while (Spaces.Count > 0)
         {
             // get a new current space from stack
             currentSpace = Spaces.Dequeue();
             // change the current space to red
             currentSpace.color = color;
             // wait
             yield return new WaitForSeconds(1);
             if (Spaces.Count > 0 && currentSpace != null)
             {
                 // turn off the current space
                 currentSpace.color = Color.white;
             }
         }
         if (P1)
         {
             GameManager.Instance.P1Position = Goal;
         }
         else
         {
             GameManager.Instance.P2Position = Goal;
         }
     }
 
     void Update () {
         
     }
 }
 
I'm not sure how the above code will help but I hope I included enough information to give you an idea. It's a square board consisting of 20 images all around it. My goal is to display a message that says "Development Time: 4 Years" after a specific space is colored red. Thank you in advance!
Your answer
 
 
             Follow this Question
Related Questions
How to make a world-space UI panel that can find an open position in the world? 0 Answers
Problems getting UI elements to activate/deactivate on mouse over? 1 Answer
A Javascript trying to access an image effect C# script 1 Answer
[C#] How to make a pathfinding system for a board game? 1 Answer
Is it possible to scroll in a InputField using a script? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                