Strange GUITexture prefab problem with pixelInset.width

Hi FOlks.

I have created a game object which I turned into a prefab called LevelBar.

I am following this tutorial from here : Unity 3D Student - 3d Modelling

Now - I have 2 scripts which are to alter the GUITexture.pixelInset.width value , one makes it bigger so the progress bar increases, one makes it smaller so the bar decreases to show progress towards a goal.

I have dragged my prefab onto my Scene, and dragged my prefab also onto my 2 scripts :

1/ http://pastebin.com/9MKk6Ckx

2/ http://pastebin.com/4Yhf0F0V

On top of all of this, my LevelBar pixelInset.width increases - but i never actually get to see the bar on screen, yet when i increase the width manually on the prefab it displays just fine. It looks like my script is now dealing with the instance of the prefab , instead it is dealing with the prefab itself…

Please help!

OK thanks to Zerot on the IRC channel on freenode.net I have an answer.

The reason this was not working was because the script was pointing to the prefab - not the instantiated version of my object.

The problem was - the blocks were not being instantiated by the scene hierarchy before runtime - they were being script instantiated.

The solution was to use:

	 var other : BlockCollider = myObject.gameObject.GetComponent("BlockCollider");

And then set the other.levelbar = theLevelBar.
theLevelBar is passed in to the script via dragging the instance onto the script in question.

All solved :slight_smile: