Hi,
I’m trying to switch the textures on 16 different prefabs that I instantiate at the same time. With the code below I have managed to do this. Unfortunately, I am now getting the warning message “InvalidCastException: Cannot cast from source type to destination type.”
setLetterVariables.Letter (System.Object points, System.Object id)". I’m quite new to Unity so I’m not sure what this means, however I would like to solve this warning before I move on. Can anyone tell me what this means and how to get rid of it?
Thanks
#pragma strict
var switchTime = 3;
var seconds = switchTime;
function Start () {
InvokeRepeating ("Countdown", 1.0, 1.0);
}
function Update () {
if (Input.GetKeyDown(KeyCode.Escape)) {
print("DEBUG: BRING UP IN GAME MENU");
}
}
function Countdown () {
seconds -= 1;
if (seconds == 0){
//print("Resetting");
seconds = switchTime;
Destroy(gameObject);
SwitchBlock();
}
}
function SwitchBlock(){
var texture = new Array ("gamepieceA",
"gamepieceB",
"gamepieceC",
"gamepieceD",
"gamepieceE",
"gamepieceF",
"gamepieceG",
"gamepieceH",
"gamepieceI",
"gamepieceJ",
"gamepieceK",
"gamepieceL",
"gamepieceM",
"gamepieceN",
"gamepieceO",
"gamepieceP",
"gamepieceQ",
"gamepieceR",
"gamepieceS",
"gamepieceT",
"gamepieceU",
"gamepieceV",
"gamepieceW",
"gamepieceX",
"gamepieceY",
"gamepieceZ");
var random_texture = Mathf.Floor(Random.Range(0,texture.length));
var new_letter : GameObject;
new_letter = Instantiate(Resources.Load("letter"), transform.position, transform.rotation);
switch(texture[random_texture]){
case "gamepieceA" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceB" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceC" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceD" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceE" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceF" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceG" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceH" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceI" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceJ" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceK" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceL" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceM" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceN" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceO" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceP" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceQ" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceR" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceS" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceT" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceU" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceV" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceW" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceX" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceY" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
case "gamepieceZ" :
new_letter.renderer.material.mainTexture = Resources.Load(texture[random_texture]);
break;
default :
print ("Got default");
}
}