- Home /
How To Make This To Work?
var NoZoom : Texture2D;
var Zoom : Texture2D;
function Update() {
if(Input.GetMouseButtonDown(0))
renderer.material.mainTexture = Zoom;
else
renderer.material.mainTexture = NoZoom;
}
im trying to change the Qui Texture when im pressing right mouse button. this doesnt work and i dont why. Coud You help me? EDIT: im getting this error:
MissingComponentException: There is no 'Renderer' attached to the "CrossHair" game object, but a script is trying to access it.
You probably need to add a Renderer to the game object "CrossHair". Or your script needs to check if the component is attached before using it.
CrossHairSniper.Update () (at Assets/CrossHairSniper.js:7)
Help?
Don't start variable names with capital letters. Other than that, perchik gave you the right answer.
Unity's compiler has some cryptic error messages, but that is not one of them.
You probably need to add a Renderer to the game object "CrossHair".
I don't think I can explain any more clearly to you what is wrong and what needs to be done than Unity already did.
Answer by perchik · Jul 26, 2013 at 07:10 PM
GetMouseButtonDown(0)
refers to the Left button on the mouse.
GetMouseButtonDown(1)
is used to catch the Right button
Answer by Kiloblargh · Jul 26, 2013 at 07:38 PM
var noZoom : Texture;
var zoom : Texture;
var theCrosshair : GUITexture;
function Update() {
if (Input.GetMouseButtonDown(0))
{
theCrosshair.texture = zoom;
}
else
{
theCrosshair.texture = noZoom;
}
}
Your problem is there's no Renderer in a GUITexture. You should always read the script reference on the component you're having trouble with.