using System; using System.Collections; using System.Collections.Generic; using System.Security.Cryptography; using UnityEngine; using Random = UnityEngine.Random; public class WizardLight : MonoBehaviour { private float range = 0; float minFlickerIntensity = 0.6f; float maxFlickerIntensity = 0.8f; float flickerSpeed = 0.05f; private HardLight2D wizardlight; private HardLight2D[] lights; private GameObject fire; private int randomizer = 0; private Transform wizardTransform; // Start is called before the first frame update void Start() { lights = FindObjectsOfType(); List finalList = new List(); string nameToLookFor = "LightWizard"; for(var i = 0; i < lights.Length; i++) { if(lights[i].name == nameToLookFor) { finalList.Add(lights[i]); } } wizardlight = finalList[0]; //firelight = FindObjectOfType(); StartCoroutine( ChangeRange()); wizardTransform = GameObject.FindGameObjectWithTag("NPC").transform; } private void Update() { StartCoroutine( ChangeRange()); wizardTransform = GameObject.FindGameObjectWithTag("NPC").transform; if (DungeonManager.hasTeleported) { Destroy(gameObject); wizardlight.enabled = false; } } void LateUpdate() { // we store current camera's position here Vector3 temp = transform.position; temp.x = wizardTransform.position.x; temp.y = wizardTransform.position.y-0.2f; transform.position = temp; } IEnumerator ChangeRange() { if (randomizer == 0) { wizardlight.Intensity = (Random.Range (minFlickerIntensity, maxFlickerIntensity)); } else wizardlight.Intensity = (Random.Range (minFlickerIntensity, maxFlickerIntensity)); randomizer = Random.Range (0, 1); yield return new WaitForSeconds(flickerSpeed); } }