Quantcast
Channel: Latest Questions by Fox-Handler
Viewing all articles
Browse latest Browse all 90

Trying to Lerp Multiple lights

$
0
0
I was following the stealth tutorial from unity and I tried adding a lerp to all the camera lights when the alarm goes off, but I get the error `Assets/Scripts/CCTVPlayerDetection.cs(64,88): error CS0165: Use of unassigned local variable `newIntensity' ` What Am I doing wrong? using UnityEngine; using System.Collections; public class CCTVPlayerDetection : MonoBehaviour { private GameObject player; private LastPlayerSighting lastPlayerSighting; private Light [] spotLights; private float lightHighIntensity = 7f; public float lightLowIntensity = 4f; void Awake() { player = GameObject.FindGameObjectWithTag(Tags.player); lastPlayerSighting = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent(); GameObject[] CameraGameObjects = GameObject.FindGameObjectsWithTag(Tags.spotLight); spotLights = new Light[CameraGameObjects.Length]; for( int i=0; i < spotLights.Length; i++) { spotLights[i] = CameraGameObjects[i].light; } } void Update() { IntruderDetect (); } void OnTriggerStay(Collider other) { if(other.gameObject == player) Vector3 relPlayerPos = player.transform.position - transform.position; RaycastHit hit; if(Physics.Raycast (transform.position,relPlayerPos,out hit)) { if(hit.collider.gameObject == player) { lastPlayerSighting.position = player.transform.position; } } } } void IntruderDetect() { float newIntensity; for(int i = 0; i < spotLights.Length; i++) { if(lastPlayerSighting.position != lastPlayerSighting.resetPosition) { newIntensity = lightHighIntensity; } else if(lastPlayerSighting.position == lastPlayerSighting.resetPosition) { newIntensity = lightLowIntensity; } spotLights[i].intensity = Mathf.Lerp (spotLights[i].intensity, newIntensity, lastPlayerSighting.fadeSpeed * Time.deltaTime); } } }

Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>