- Home /
"Show GUITexture within distance" issue
Hi, i was wondering how to do this.... I want to make it so when a car goes in a building. It shows a guitexture. I was thinking about doing it where, when the car is near a gameobject in the builing, enable a button. i also tried doing where you have a collider and the car will show the texture when it is touching the collider. this way didnt work
im going to stick to the first.
When i run this script. it only works for one building. when i duplicate it, it doesn't work. Itll only work for one, no matter how many i have. Can someone please help?
#pragma strict
var RepairCubeTeller : Transform;
var guitexture : GUITexture;
function Update () {
var dist : float = Vector3.Distance(RepairCubeTeller.position, transform.position);
if(dist<10)
{
guitexture.enabled = true;
}
else
{
guitexture.enabled = false;
}
}
Do you have multiple cars? Is the 'RepairCubeTeller' one of your cars? I assume you initialize each script with a different guiTexture?
Yes. I have 4 cars. The repaircubeteller is a game object attached to the main camera. The main camera switches between cars. The script is attached to a game object inside the buildings. The same script is attached to all of the game objects inside the buildings.
The script looks fine, so I'm trying to understand what you are seeing. Does it not fire for the other positions, or is the GUITexture is the wrong place, or...? Do you have just a single GUITexture object or do you have one for each place this script is attached? You have initialize the 'guitexture' variable in the Inspector?
Ya it's weird, I made one building with the script and it worked. But as soon as I duplicate it, suppose it did five. It only works for one of those five buildings. I'm really confused. Thanks for the help.
What if I made it so when it collides with that building and it's duplicated buildings, it shows the GUI texture. Would that work? How should I approach that?
Your answer
![](https://koobas.hobune.stream/wayback/20220613141059im_/https://answers.unity.com/themes/thub/images/avi.jpg)