Question by
lucas216erickson · Jul 07, 2016 at 12:08 AM ·
nullreferenceexceptionprojector
Projector does not contain a definition for 'material'
I'm trying to project an underwater caustics effect for my game, but I can't figure out how to assign the material of the projector.
Here's my original code:
using UnityEngine;
using System.Collections;
public class Projector : MonoBehaviour {
public float fps = 30.0f;
public Texture2D[] frames;
private int FrameIndex;
private Projector CausticsProjector;
void Start()
{
CausticsProjector = GetComponent<Projector> ();
NextCausticsFrame ();
InvokeRepeating ("NextCausticsFrame", 1 / fps, 1 / fps);
}
void NextCausticsFrame()
{
//Here's where I get the error
CausticsProjector.material.SetTexture("_ShadowTex", frames [FrameIndex]);
FrameIndex = (FrameIndex + 1) % frames.Length;
}
}
After reading a few things, I thought changing it to this might fix it:
GetComponent<Projector>().material.SetTexture("_ShadowTex", frames [FrameIndex]);
but that hasn't fixed it either. I also am getting a lot of "The object of type object has been destroyed, but you are still trying to access it," messages.
Comment
Answer by lucas216erickson · Jul 07, 2016 at 08:09 PM
Ok, it works in any new script I make, I just created a new script and copied the old one. Everything works fine now.