Point light intensity 1->1,50

Hello, I made Point light.
I set intensity to 1.0 I want to ask you how to make script which will
set intensity to 1.50 when First Character controller will be near the Point light.
How to do that?
I know that I can use Tag to do it but I don’t know how.

Regards.

You can attach a collider set as a trigger on the light object and use OnTriggerEnter/Exit to determine if the player is inside, or you can use Vector3.Distance with the player and light positions and adjust the light accordingly

Hey, yes, I was thinking about the same thing but the problem is that I need to get some example.

Oh ok, here’s an example of using Vector3.distance for it, this would be on the gameobject with the light:

float light_range = 10f;
Transform player;

void Awake(){
    player = GameObject.Find("Player").transform;
}

void Update(){
    if(Vector3.Distance(player.position, transform.position) < light_range){
        light.intensity = 1.5f;
    }
    else{
        light.intensity = 1.0f;
    }
}

It could also be written in one line using the ternary operator:

light.intensity = (Vector3.Distance(player.position, transform.position) < switch_range)? 1.5f : 1.0f;

Thx, But there is something wrong with this script

Yeah it was just a small example, you will need the UnityEngine namespace at the top of the script as well as the scripts class name:

using UnityEngine;

public class light_script : MonoBehaviour {

Thank you. Work perfect.

No problem!