K
K
Kot Kotov2020-02-05 09:00:57
C++ / C#
Kot Kotov, 2020-02-05 09:00:57

Error when trying to change the color of Light2D. What to do?

void Awake()
  {
    Light2D light = transform.GetComponent<Light2D>();
    Color prettyColor = new Color (255, 255, 255);
    light.color=prettyColor;
  }

an error appears on the line light.color=prettyColor;(NullReferenceException: Object reference not set to an instance of an object
Player.Awake () (at Assets/Scripts/Player.cs:31))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question