- Home /
guiText.text = gameobect.name Not Working?
When you mouse over a gui texture, I would like you to be able to see its preset, in - game, name.
To achieve this I am using:
if (guiTexture.pixelInset.Contains(Input.mousePosition)) {
guiText.text = gameObect.name;
}
The code you see works sometimes, but not all the time.
Thanks for reading.
Mithos
Answer by ScroodgeM · Aug 03, 2012 at 07:49 AM
replace
guiTexture.pixelInset.Contains(Input.mousePosition)
with
guiTexture.HitTest(Input.mousePosition)
pixelInset is not a screen-based coords, this is relative to it's position, so don't compare it with mouse position directly. this can work only in 0,0 position of guiTexture
@Scroodge, this was the problem. HitTest Worked.
Thanks a bunch!
Answer by Eric5h5 · Aug 03, 2012 at 07:23 AM
There is no GUITexture.text, as you can see in the docs. GUITextures can't have text, they are textures. GUIText.text on the other hand is something that exists.
I'm so sorry, its early in the morning. I am getting no errors and it is in - fact already guitext in code,
sorry for the confusion.