#changing text color
1 messages · Page 1 of 1 (latest)
perfect
how do u currently check if a button is selected
i dont want to change manually the color
perfect
how do u currently check if button is selected?
i dont have nothing when the botton is clicked
yeah thats not smart
so now i need to spoonfeed u the answer bcs u didnt pay attention
make a new script
maybe when you need help i will help you back
ok
done
usually in this part i ask chat gpt or i check online if someone have done it
chatgpt is bad for code
perfect
i move it with arrows
i have a lot of thing that i want to do with it
give button a collider
i want that i can click botton with enter when you are on it
and the text need to turn yellow
ok
i dont knwo why i cant see the box collider
btw make the collider a trigger
ok
clikc this
done it
and now?
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')
code like this?
yes after that one
its give me 6 error
sorry i didnt understand
ok
still a lot of error
CTRL A, CTRL V here pls
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);
}
}
}
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
4 error
work or not
what error
ok replace with
new Color(1, 1, 0, 0);
and
new Color(1, 1, 1, 0);
put this script on ur heart
still error
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
yes
with what?
anything u like
so i need to make 2 script
one is this that you made
im trying to use Unity's Color class
but u already have a script made urself called Color
and it gets in the way
the color script is yours
so u just need to rename that Color script to something else so i can use Unity's color
o
well rename to ChangeColor
copypaste this
ok
3 error
yes
no more clash of clans
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
its say this
Rename script FILE to ChangeColor.cs
it probably still called Color.cs
then it wont work
name needs to be same as class name
the name is changecolor.cs
its right
its whit the capital letter
can u play game and sit on a button with heart and show me the component settings of that button's text?
text
what i need to add at the text object?
my poor village
done
screenshoit
is that the heart object
what
what object is this
heart
screenshot of whole screen pls
i was missing the script, i put it now
but now i have a problem
add script again
and replay
because it wont keep script on it if u add it during playmode
ok
add script to heart again
you are like my angel
no im coming from hell
another one?
yes because the one u added is gone now
why is gone?
ok
what
name???
just add script to ur object
like u did a second ago
just do that again
like this?
no sorry
i told u to do it
ok well dont worry just clikc the NewGame object
ok and?
then u see al the way at the top of th hierarchie
'Tag' and 'Layer'
click tag and create new tag called Button
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
edited
still dont work i dont know why
no color on new game
did u give collider
yes
also why is color still yellow on reset
are ur colliders positioned well
show me the green outline of ur colliders
and heart
now with your new code is correct
then idk
study hard in class i guess
would be much easier if u just use mouse to select
life easy? not for me hahaha
yeah well its gonna be harder the more clash of clans u play
so how can i repair?
My village need me
ITS WORK
NOW I WILL MAKE A STATUE OF YOU IN MY GAME
gg