hi guys, im having trouble using guiTexture.texture, at the moment my understanding if that with guiTexture your using the texture thing you create from GameObject > create other > GUI Texture. however in my script i cannot set the guitexture to a var (var Textr : Texture2D;) also i cant use GetComponent(Name).enabled = true; but this may be becuase it isn’t assigned, im not sure. thanks!
i managed to set the guitexture to my var by changing it to GUITexture instead of texture2D.
heres my script
var ShowDrallor = false;
var Drallor : Texture;
var Loc : Vector2 = Vector2 (500,200);
var Loc2 : Vector2 = Vector2 (400,100);
var Fitd = 0;
var DrallorText : Texture;
var DrallorGUI : GUITexture;
function OnTriggerEnter () {
ShowDrallor = true;
TimerGo ();
GlobalTrigger.CurLoc = Drallor;
GetComponent("DrallorText").enabled = true;
}
function OnGUI () {
if(ShowDrallor) {
//GUI.DrawTexture(Rect(Loc.x,Loc.y,Loc2.x,Loc2.y), DrallorText, ScaleMode.ScaleToFit, true, Fitd);
guiTexture.texture = DrallorGUI;
}
}
function TimerGo () {
yield WaitForSeconds (3);
ShowDrallor = false;
}
It looks like you editted your original post to answer (some of) your own questions, so I’m not sure what your remaining questions are… What ‘weird errors’ are you getting? Where are null reference errors being reported? How does the code not work? When seeking help with script errors, it always helps to post the specific errors you’re getting.
sorry =) i thought somone would have been able to see what was wrong with my script straight up becuae ive pretty muched just put in random stuff to try and get it to work. the error is “InvalidCastException: Cannot cast from source type to destination type” and thats at the line guiTexture.texture = DrallorGUI; .
im ausuming this means its having trouble converting/using it with the var: var DrallorGUI : GUITexture;
im not 100% sure though and the documentation isnt really clear enough for me to understand. thanks
ok, so after playinf around a bit ive set the var to a texture2D once again and instead of selecting a already made GUITexture i just added any old texture, im hoping what the script will do is create, or simulate one? Its weird it seems to be working and everything but i get the error "Missing Component EXceptioon: There is no ‘GUITexture’ attached to the ‘DrallorTrig’ game object, but a script is trying to acess it.
edit, it doesnt work. Script just hadnt updated after save for some weird reason. problem still occours. can anyone just show me a small example of what is needed? thanks
The error means that the GameObject the script is attached to doesn’t have a GuiTexture component. If that component is missing, there’s nothing for ‘guiTexture’ to reference. I’m not sure what you mean when you say you hope the script will ‘create or simulate’ a GUITexture. You need to have an existing GUITexture component, or you need to create on on the fly. It wont happen automatically.
yes, but as i posted above it wont let me assign a guiTexture , to the variable. Im ausuming you do it like you would with a transform variable, just drag and drop the object to the field, It wont allow me to do this, this is why i tryed all kinds of stuff like guiTexture as a variable rather than Texture2D
You add a GUITexture component to the game object via the Component → Rendering → GUITexture menu. Then, once you have a GUITexture component, you can access it through the guiTexture variable, including setting the image it shows through guiTexture.texture. If for some reason you really do need to create the GUITexture component via script, you would need to do so with AddComponent().
Then Ive tryed to drag and drop this to the variable zone on the script:
it Will not let me drag and drop the GUITextue, i do get a small error cricle to say i cant do this (my cursor) but as printscreens hide your cursor you cannot see it.
Next, i tried to click the small circle to the right of the variable and search for the guitexture, it cannot find it becuase again it wont allow me to assign it.
What do you mean, why would that make a difference? As I’ve already pointed out, the ‘guiTexture’ property is a reference to the GUITexture component attached to the same game object the script is attached to. You’re missing something fundamental somewhere here I think…
ok, well i cant see what XD. heres what im doing 1. Creating a GUITexture from Component → Rendering → GUITexture menu, then i assign my script to the GUITexture, then i drag and drop the guitexture to the variable field, what could i possibly be missing?
If you’re dragging the GUITexture onto an inspector field for a variable in a script attached to a different game object, that script is still not going to be able to use the guiTexture member. You can only access the guiTexture property if the object the script is attached to has a GUITexture component.
Click on the “Missing Component EXceptioon: There is no ‘GUITexture’ attached to the ‘DrallorTrig’ game object, but a script is trying to acess it.” error message in the console; you should see an item in the scene hierarchy view highlighted briefly in yellow. That’s the object the scrip is attached to. Click on it to open the Inspector for that object. In the Inspector window, do you see a GUITexture component listed, for that object?