Hi, i am very noob in Unity and in programming. I try to follow some tutorials but in one point of the track i get stuck with this error:
Implicit downcast from ‘Object’ to ‘UnityEngine.GUITexture’.
InvalidCastException: Cannot cast from source type to destination type.
Showlives…ctor () (at Assets/Juego Shooter/Scripts/Showlives.js:4)
I see that the problem is in the line 4 of my code but i don´t know what are wrong.
#pragma strict
var livetexture:Texture;//La textura que corresponde a las vidas restantes
var lives:GUITexture[]=[null,null,null];//el numero de vidas
var texto:GUIText;//El texto que indica fin de juego
var texto2:GUIText;//El texto que indica las instrucciones
function Update () {
if(Globals.Lives==3)
{
lives[2].color.a=128;
lives[1].color.a=128;
lives[0].color.a=128;
}
if(Globals.Lives==2)
{
lives[2].color.a=0;
lives[1].color.a=128;
lives[0].color.a=128;
}
if(Globals.Lives==1)
{
lives[2].color.a=0;
lives[1].color.a=0;
lives[0].color.a=128;
}
if(Globals.Lives==0)
{//cuando el numero de vidas llega a 0, se muestra pantalla Game Over y si pulsamos boton asignado vamos a menu principal
lives[2].color.a=0;
lives[1].color.a=0;
lives[0].color.a=0;
texto.text="Game Over";
texto2.text="Pulsa ESPACIO para Continuar";
if(Input.GetButtonDown("Jump"))
{
Globals.Levels=0;
Application.LoadLevel(Globals.Levels);
}
}
}