Y
Y
Yura Berezovsky2016-10-02 22:50:43
C++ / C#
Yura Berezovsky, 2016-10-02 22:50:43

Where is my logical error (The essence of the script is that when the Light component is turned off, the sphere should change color to white)?

using UnityEngine;
using System.Collections;

public class LightsONSctript : MonoBehaviour {
  private Light myLight;


  void Start () {
    
    myLight = GetComponent<Light> ();
  }
  

  void Update () {



    if (Input.GetKeyDown (KeyCode.L)) {
      GetComponent<Renderer> ().material.color = Color.yellow;
      myLight.enabled = !myLight.enabled;
      Debug.Log("Action");
    }
    if (myLight.enabled = false) {
      GetComponent<Renderer> ().material.color = Color.red;
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VitGun, 2016-10-03
@VitGun

And it changes to red, right?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question