Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Fading Out Coroutine: The name 'lerpDuration' and 'targetMeshrenderer' does not exist in current context

$
0
0
Hello, I am trying to make a script that makes an object fade out when I press Q using a coroutine, but I get the errors "The name 'lerpDuration' does not exist in current context" and "The name 'targetMeshrenderer' does not exist in current context" I have no idea how to solve it. If anyone could take a look at the code I'd be grateful. using System.Collections; using System.Collections.Generic; using UnityEngine; public class ObjectController : MonoBehaviour { private Color targetColor; private Color currentColor; public GameObject obj; public float fadeSpeed; // Start is called before the first frame update void Start() { targetColor = obj.GetComponent().material.color; targetColor.a = 0f; } // Update is called once per frame void Update() { if (gameObject.activeSelf && Input.GetKeyDown(KeyCode.Q)) { StartCoroutine(LerpMeshrendererColor(targetMeshrenderer, lerpDuration, currentColor, targetColor)); } } private IEnumerator LerpMeshrendererColor(MeshRenderer targetMeshrenderer, float lerpDuration, Color currentColor, Color targetColor) { float lerpStartTime = Time.time; float lerpProgress; bool lerping = true; while (lerping) { yield return new WaitForEndOfFrame(); lerpProgress = Time.time - lerpStartTime; if (targetMeshrenderer != null) { targetMeshrenderer.material.color = Color.Lerp(currentColor, targetColor, lerpProgress / lerpDuration); } else { lerping = false; } if (lerpProgress >= lerpDuration) { lerping = false; } } yield break; } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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