Hello, so i have some gameobjects (Lamps) who have the same tag name (Lights), and also i have a function that when i click on them, it turns off the component “Light” of those gameobjects, the thing is that when i click on one, all the lights are turned off in every lamp.
How can i call only 1gameobject the one im clicking to run the function to turnoff the light?
*Also i want to execute this function only if my player is standing next to the gameobject im clicking on.
Thanks!
using System.Collections;
public class StreetLampFunction : MonoBehaviour {
private Light myLight;
void Start ()
{
myLight = GetComponent<Light>();
}
void Update()
{
if (Input.GetMouseButtonDown(1))
{
RaycastHit hitInfo = new RaycastHit();
bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
if (hit)
{
if (hitInfo.transform.gameObject.tag == "Light")
//add code comparing vector position of the player and the vector position of the raycast hit position, if its next to it, execute the next line...
{
myLight.enabled = !myLight.enabled;
}
}
}
}
}