UnityEngine.Component (camera) does not contain a definition for projectionMatrix

Hi
trying to use the following code on my camera(from this thread)
but get the following error (referring to this line)

camera.projectionMatrix = MatrixLerp(src, dest, (Time.time - startTime) / duration);

Asked google but can’t find a solution…

using UnityEngine;
using System.Collections;
[RequireComponent (typeof(Camera))]
public class MatrixBlender : MonoBehaviour
{
public static Matrix4x4 MatrixLerp(Matrix4x4 from, Matrix4x4 to, float time)
{
Matrix4x4 ret = new Matrix4x4();
for (int i = 0; i < 16; i++)
ret[i] = Mathf.Lerp(from[i], to[i], time);
return ret;
}
private IEnumerator LerpFromTo(Matrix4x4 src, Matrix4x4 dest, float duration)
{
float startTime = Time.time;
while (Time.time - startTime < duration)
{
camera.projectionMatrix = MatrixLerp(src, dest, (Time.time - startTime) / duration);
yield return 1;
}
camera.projectionMatrix = dest;
}
public Coroutine BlendToMatrix(Matrix4x4 targetMatrix, float duration)
{
StopAllCoroutines();
return StartCoroutine(LerpFromTo(camera.projectionMatrix, targetMatrix, duration));
}
}

Don’t trust 7 year old code :slight_smile:

Unity deprecated those shortcut properties and made them all return Component types instead. You should use GetComponent() instead. Also - Google gives you a ton of examples: Type `UnityEngine.Component' does not contain a definition - Google Search

Good advice! I probably shouldn’t trust code more than a year old the way things keep changing