- Home /
Question by
cenkbz3589 · Apr 23, 2021 at 05:56 PM ·
scripting problemlightingunity 2dintensity
Light intensity Problem in unity 2D
Hello guys, i'm making 2D game and i'm still learning. i want to change Light intensity by pressing a key but its give me eror "NullReferenceException: Object reference not set to an instance of an object" can you tell me what to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.Scripting;
using UnityEngine.Experimental.Rendering.LWRP;
using UnityEngine.Experimental.Rendering.Universal;
public class LightScript : MonoBehaviour
{
public UnityEngine.Experimental.Rendering.Universal.Light2D MyLight;
public bool isInRange = false;
void Start()
{
MyLight = GetComponent<UnityEngine.Experimental.Rendering.Universal.Light2D>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("İnHomePlayer"))
{
isInRange = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.CompareTag("İnHomePlayer"))
{
isInRange = false;
}
}
private void Update()
{
if(isInRange == true)
{
if (Input.GetKeyDown(KeyCode.E))
{
MyLight.intensity = 1;
}
}
}
}
Comment
Well, that error is because the object/component youre trying to reference is not assigned to the variable. Can you drag and drop it into the variable to be sure its assigned?
Your answer
Follow this Question
Related Questions
Shader not changing according to scene light in real time. 1 Answer
Unity won't finish opening Visual Studio 0 Answers
Unity 8.1 How to get text via script 0 Answers
Prevent light combining with other lights 0 Answers
Is it possible to rotate the environment's reflection source at runtime? (C#) 1 Answer