Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by perfect_harmonii · May 09, 2018 at 07:20 PM · scripting problemuser interfaceimage effectstop-downboardgame

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

147 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges