#changing text color

1 messages · Page 1 of 1 (latest)

drifting garden
#

started thread

valid vapor
#

perfect

drifting garden
#

how do u currently check if a button is selected

valid vapor
#

i dont want to change manually the color

drifting garden
#

no shit u need to do it with code lol

#

u can automate it

valid vapor
#

perfect

drifting garden
#

how do u currently check if button is selected?

valid vapor
#

i dont have nothing when the botton is clicked

drifting garden
#

clicking isnt selecting

#

i mean

#

how do ucheck if ur heart is on NEW GAME

valid vapor
#

i dont know

#

that what i need to do

drifting garden
#

have u followed unity and c# courses

#

do u know how to code

valid vapor
#

a little bit

#

i didnt listen on class

#

i was playng clash of clans

drifting garden
#

yeah thats not smart

#

so now i need to spoonfeed u the answer bcs u didnt pay attention

#

make a new script

valid vapor
#

maybe when you need help i will help you back

valid vapor
#

done

#

usually in this part i ask chat gpt or i check online if someone have done it

drifting garden
#

chatgpt is bad for code

valid vapor
#

perfect

drifting garden
#

the way u move ur heart is a problem

#

bcs its gonna be hard to check

valid vapor
#

i move it with arrows

drifting garden
#

anyway what u can do

#

u can check by collision

valid vapor
#

i have a lot of thing that i want to do with it

drifting garden
#

give button a collider

valid vapor
#

i want that i can click botton with enter when you are on it

#

and the text need to turn yellow

valid vapor
drifting garden
#

write in script:

#

private void OnTriggerEnter2D

valid vapor
#

i dont knwo why i cant see the box collider

drifting garden
#

btw make the collider a trigger

valid vapor
drifting garden
#

clikc this

valid vapor
#

done it

valid vapor
drifting garden
#
private void OnTriggerEnter2D(Collider2D col)
{
  if (col.gameObject.CompareTag("Button")
  {
    col.transform.GetComponent<Text>().Color = new Color(255, 255, 0, 0);
  }
}

private void OnTriggerExit2D(Collider2D other)
{
  if (other.gameObject.CompareTag("Button")
  {
    other.transform.GetComponent<Text>().Color = new Color(255, 255, 255, 0);
  }
}
#

give all buttons the Button tag

#

(create new tag called 'Button')

valid vapor
#

code like this?

drifting garden
#

write 'using UnityEngine.UI;' at the top

#

line 1

#

of ur script

valid vapor
drifting garden
#

yes after that one

valid vapor
#

its give me 6 error

drifting garden
#

change color to new Color(1, 1, 0, 0) and (1, 1, 1, 0)

#

the values

valid vapor
#

sorry i didnt understand

drifting garden
#

it says now 255 255 255 0

#

make it 1 1 1 0

valid vapor
#

ok

drifting garden
#

basicaly

#

change 255 for 1

#

in both of them

valid vapor
#

still a lot of error

drifting garden
#

CTRL A, CTRL V here pls

valid vapor
#

ofc

#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Color : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    
}
private void OnTriggerEnter2D(Collider2D col)
{
    if (col.gameObject.CompareTag("Button")
    {
        col.transform.GetComponent<Text>().Color = new Color(1, 1, 1, 0);
    }
}

private void OnTriggerExit2D(Collider2D other)
{
    if (other.gameObject.CompareTag("Button")
    {
        other.transform.GetComponent<Text>().Color = new Color(1, 1, 1, 0);
    }
}

}

drifting garden
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Color : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.CompareTag("Button"))
        {
            col.transform.GetComponent<Text>().color = Color.yellow;
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Button"))
        {
            other.transform.GetComponent<Text>().color = Color.white;
        }
    }
}

edited

valid vapor
#

4 error

drifting garden
#

try again

#

copy paste what i did

valid vapor
#

now 2 error

#

LETS GOù

drifting garden
#

work or not

valid vapor
#

not work

#

but less error

drifting garden
#

what error

valid vapor
drifting garden
#

ok replace with
new Color(1, 1, 0, 0);
and
new Color(1, 1, 1, 0);

#

put this script on ur heart

valid vapor
#

still error

drifting garden
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ChangeColor : MonoBehaviour
{
    private Text currentCollidedButtonText;

    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.CompareTag("Button"))
        {
            text = col.transform.GetComponent<Text>();

            text.color = Color.yellow;

            if (currentCollidedButtonText) currentCollidedButtonText.color = Color.white;
            currentCollidedButtonText = text;
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Button"))
        {
            other.transform.GetComponent<Text>().color = Color.white;
        }
    }
}
#

do u already have a script called Color.cs

valid vapor
#

yes

drifting garden
#

delete

#

or rename

valid vapor
#

with what?

drifting garden
#

anything u like

valid vapor
#

so i need to make 2 script

drifting garden
#

no

#

look

valid vapor
#

one is this that you made

drifting garden
#

im trying to use Unity's Color class

#

but u already have a script made urself called Color

#

and it gets in the way

valid vapor
#

the color script is yours

drifting garden
#

so u just need to rename that Color script to something else so i can use Unity's color

#

o

#

well rename to ChangeColor

valid vapor
#

ok

drifting garden
#

after this pls pay attention to classes 🙂

#

then u can easily make it urself

valid vapor
#

3 error

valid vapor
#

no more clash of clans

drifting garden
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ChangeColor : MonoBehaviour
{
    private Text currentCollidedButtonText;

    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.CompareTag("Button"))
        {
            Text text = col.transform.GetComponent<Text>();

            text.color = Color.yellow;

            if (currentCollidedButtonText) currentCollidedButtonText.color = Color.white;
            currentCollidedButtonText = text;
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Button"))
        {
            other.transform.GetComponent<Text>().color = Color.white;
        }
    }
}
#

edited

valid vapor
#

ok no error, lets test

#

dosent work

#

no error but dosent work

drifting garden
#

did u set tags

#

to buttons

#

did u set colliders

valid vapor
#

its say this

valid vapor
#

wait

drifting garden
#

Rename script FILE to ChangeColor.cs

#

it probably still called Color.cs

#

then it wont work

valid vapor
drifting garden
#

name needs to be same as class name

valid vapor
#

its right

drifting garden
#

use capital leter

#

ChangeColor

valid vapor
#

its whit the capital letter

drifting garden
#

can u play game and sit on a button with heart and show me the component settings of that button's text?

valid vapor
#

ok

drifting garden
#

text

valid vapor
#

what i need to add at the text object?

drifting garden
#

..

#

rly pay attention to class next time bro

valid vapor
#

my poor village

drifting garden
#

click Text object below NewGame

#

no your poor concentration

valid vapor
drifting garden
#

screenshoit

valid vapor
drifting garden
#

click heart object

#

did u give it the ChangeColor script

#

to heart

valid vapor
drifting garden
#

is that the heart object

valid vapor
drifting garden
#

what

drifting garden
valid vapor
#

heart

drifting garden
#

screenshot of whole screen pls

valid vapor
#

i was missing the script, i put it now

drifting garden
#

yes good

#

now stop playmode

valid vapor
#

but now i have a problem

drifting garden
#

add script again

#

and replay

#

because it wont keep script on it if u add it during playmode

valid vapor
drifting garden
#

yes

#

stop game

valid vapor
#

ok

drifting garden
#

add script to heart again

valid vapor
#

you are like my angel

drifting garden
#

no im coming from hell

valid vapor
drifting garden
#

yes because the one u added is gone now

valid vapor
#

why is gone?

drifting garden
#

because it is

#

i already told u why

valid vapor
#

ok

valid vapor
#

what name i give to it?

drifting garden
#

what

#

name???

#

just add script to ur object

#

like u did a second ago

#

just do that again

valid vapor
#

like this?

drifting garden
#

gg

#

did u set button object tags to 'Button'

valid vapor
#

no sorry

drifting garden
#

i told u to do it

valid vapor
#

sorry i was confused

#

too many thing at the same time

drifting garden
#

ok well dont worry just clikc the NewGame object

valid vapor
#

ok and?

drifting garden
#

then u see al the way at the top of th hierarchie

#

'Tag' and 'Layer'

#

click tag and create new tag called Button

valid vapor
#

ok

#

and now i do this with all bottons right?

drifting garden
#

add this tag to NewGame Reset and Option

#

ye

#

then try it

valid vapor
drifting garden
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ChangeColor : MonoBehaviour
{
    private Text currentCollidedButtonText;

    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.CompareTag("Button"))
        {
            Text text = col.transform.GetChild(0).GetComponent<Text>();

            text.color = Color.yellow;

            if (currentCollidedButtonText && text != currentCollidedButtonText) currentCollidedButtonText.color = Color.white;
            currentCollidedButtonText = text;
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Button"))
        {
            other.transform.GetChild(0).GetComponent<Text>().color = Color.white;
        }
    }
}
#

edited

valid vapor
#

it works but in a strange way

#

on option and reset its work but on new game notù

drifting garden
#

edited

valid vapor
#

still dont work i dont know why

drifting garden
#

edited

#

now should work

valid vapor
#

no color on new game

drifting garden
#

did u give collider

valid vapor
#

yes

drifting garden
#

also why is color still yellow on reset

#

are ur colliders positioned well

#

show me the green outline of ur colliders

valid vapor
drifting garden
#

and heart

valid vapor
drifting garden
#

does have btton tag

#

show me newgame has button tag

valid vapor
#

no

drifting garden
#

tag

#

all the way at the top

#

above name

valid vapor
drifting garden
#

then idk

#

study hard in class i guess

#

would be much easier if u just use mouse to select

valid vapor
#

life easy? not for me hahaha

drifting garden
#

yeah well its gonna be harder the more clash of clans u play

valid vapor
#

so how can i repair?

valid vapor
#

ITS WORK

#

NOW I WILL MAKE A STATUE OF YOU IN MY GAME

drifting garden
#

gg