100 days of Unity Scripting

 

DAY #001

Turning on/off lights with “p” key.

Main points covered

#Input.GetKey

#.enabled

C# script (attached to the light):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OnOffLight : MonoBehaviour {

public Light myLight;

void Update () {
if (Input.GetKey (“p”)){
myLight.enabled = true;
}else{
myLight.enabled = false;
}
}
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *