texture change problem

HI all,

I have copyed a script from the bbs,and this script is for controlling the texture change. I want to use the mouse click instead of keyborad, so I modified the script a little, but i got an error, "Object reference not set to an instance of an object"

Hope for reply.Thanks.

The coder is as below:

function Update ()

{ var ray3 = Camera.main.ScreenPointToRay(Input.mousePosition); var hit3 : RaycastHit;

if (Physics.Raycast(ray3,hit3) && Input.GetMouseButtonDown(0))

//if(Input.GetKey ("1") ) { var texture:Texture2D = Resources.Load("bed1");

if(texture) { Debug.Log("Texture Loaded Sucessfully..."); renderer.material.mainTexture = texture; } else { Debug.Log("Unable to Load texture..."); } } }

Based on your script, Your "main camera" is the only thing that was not checked and as per what Proclyon mentioned, you have an unassigned object that you're using. Please check that your camera of interest is actually tagged as the "main" camera.