Skip to content

Instantly share code, notes, and snippets.

@edwios
Created August 22, 2019 01:46
Show Gist options
  • Save edwios/c0e740521aae055461302fd052d175a3 to your computer and use it in GitHub Desktop.
Save edwios/c0e740521aae055461302fd052d175a3 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class changecolor : MonoBehaviour
{
public Color[] colors;
private Vector3 positionxyz;
public Color Rcolor;
void OnTriggerEnter(Collider other)
{
Rcolor = colors[Random.Range(0, colors.Length)];
gameObject.renderer.material.color = Rcolor;
positionxyz = transform.position;
GameObject lightC = new GameObject();
lightC.name = "discolight";
lightC.AddComponent<Light>();
lightC.transform.position = positionxyz;
lightC.light.color = Rcolor;
lightC.light.range = 2.579712f;
lightC.light.intensity = 1;
lightC.light.renderMode = LightRenderMode.ForcePixel;
}
void OnTriggerExit(Collider other)
{
Destroy(GameObject.Find("discolight"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment