x


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..."); } } }

more ▼

asked Dec 08 '10 at 11:26 AM

hawaiimao gravatar image

hawaiimao
1 1 1 1

The error message means you are trying to use something that isn't actually something but just a bunch of reserved memory with nothing in it. Pretty much like an empty cookie jar and a hungry person, it's not gonna work out untill there is something in it. Can you see in the error message what was supposed to be in the jar? It could be a couple of things that's wrong. Also the formatting of the question needs a spit-shine

Dec 08 '10 at 11:35 AM Proclyon
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Dec 08 '10 at 01:41 PM

denewbie gravatar image

denewbie
717 3 3 17

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1089
x262

asked: Dec 08 '10 at 11:26 AM

Seen: 698 times

Last Updated: Dec 08 '10 at 11:26 AM