Hey developers! I get the error in the description (InvalidCastException: Cannot cast from source type to destination type.) while trying to run the following script
SNIP
case "Player1":
gameObject.guiTexture.enabled = true;
guiTexture.texture = player1; //Error here
break;
What's wrong is that `player1` doesn't contain information for a `Texture` type and/or has already been typed as something else. `GUITexture.texture` is expecting an object of type `Texture` and you are passing it a different type.
What is `player1`? It is obviously not a `Texture`. You will need to include more code than just this for anyone to conclusively tell you why it isn't a Texture.
As a rule, try to always define your variables in a strict manner by stating its type...
var player1: GuiTexture;
That way the error messages will make more sense, and the code will be much less prone to mistakes and run-time errors.
In fact, I would recommend adding
#pragma strict
to the start of your javascript files to force the compiler to complain about issued that usually it will "let slide".