Hello , im very new with unity and #C
i try to add new Object in script
for example in script have only 2 object SnowMan and SnowTree i try to add more object by copy past
but when i want Chang or add new name for example monster ,it give me this massage
The exact error message is here: NullReferenceException: Object reference not set to an instance of an object
THIS THE FULL Script
using UnityEngine;
using System.Collections;
using Vuforia;
public class MainController : MonoBehaviour
{
//[SerializeField]
//protected RenderTextureCamera _SnowManRTC;
//[SerializeField]
//protected RenderTextureCamera _SnowTreeRTC;
private IEnumerator _SendTexture(GameObject go, RenderTexture rt)
{
go.SetActive(false);
//yield return new WaitForSeconds(0.F);
yield return new WaitForEndOfFrame();
//var rt = RenderTextureCamera.CameraOutputTexture;
var FrameTexture = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
RenderTexture.active = rt;
FrameTexture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
RenderTexture.active = null;
FrameTexture.Apply();
go.GetComponent().ApplyTexture(FrameTexture);
go.SetActive(true);
}
void OnGUI()
{
//return;
//if (_snowManGo != null && GUILayout.Button(“Apply Color to SnowMan”))
//{
// StartCoroutine(_SendTexture(_snowManGo));
//}
//if (_snowManGo != null && GUILayout.Button(“Apply Color to SnowTree”))
//{
// StartCoroutine(_SendTexture(_snowTreeGo));
//}
}
private GameObject _snowManGo;
private GameObject _snowTreeGo;
public void OnTrackingFound(GameObject go)
{
print("OnTrackingFound " + go);
switch (go.name)
{
case “snowman”:
_snowManGo = go;
if (RenderTextureCamera.CameraOutputTexture != null)
StartCoroutine(_SendTexture(_snowManGo, RenderTextureCamera.CameraOutputTexture));
break;
case “snowtree”:
_snowTreeGo = go;
if (RenderTextureCamera.CameraOutputTexture != null)
StartCoroutine(_SendTexture(_snowTreeGo, RenderTextureCamera.CameraOutputTexture));
break;
}
}
public void OnTrackingLost(GameObject go)
{
print("OnTrackingLost " + go);
switch (go.name)
{
case “snowman”:
_snowManGo = null;
break;
case “snowtree”:
_snowTreeGo = null;
break;
}
}
}
Also, paste the full error message. It includes line numbers - we’re not going to look through the entire script to find the error.
(and your code will have line numbers on it if you used code tags)