gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
this is not working at all, rewrite using System.Collections; using…
- User
this is not working at all, rewrite
using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine;
public class LightFlicker : MonoBehaviour { public Material material; private Light lightSource; private Renderer rendererMaterial; private MaterialPropertyBlock propertyBlock; private float flickerInterval;
codevoid Start() { lightSource = GetComponentInChildren<Light>(); rendererMaterial = GetComponent<Renderer>(); propertyBlock = new MaterialPropertyBlock(); flickerInterval = Random.Range(30f, 90f); } void Update() { if (Time.time % flickerInterval < Time.deltaTime) if (Random.Range(0f, 1f) < Time.deltaTime) { lightSource.enabled = false; propertyBlock.SetColor("_EmissionColor", Color.black); rendererMaterial.SetPropertyBlock(propertyBlock); Invoke("ResetLight", Random.Range(0.2f, 1f)); } } void ResetLight() { lightSource.enabled = true; propertyBlock.SetColor("_EmissionColor", material.GetColor("_EmissionColor")); rendererMaterial.SetPropertyBlock(propertyBlock); }}
- Assistant