- Home /
Personaje cambie de sprite al teleportarse [Characters change sprite to teleport]
Hola a todos, vereis he estado buscando por internet pero no he podido encontrar nada que me ayude. Yo he hecho el siguiente script por el cual mi personaje al entrar en el se teleporta a otro sitio:
[Hi all, you will see I have been looking online but I could not find anything to help me . I made the following script by which my character to enter it teleports to another site :]
public Transform exit;
static Transform last;
void OnTriggerEnter2D ( Collider2D other )
{
if (exit == last)
return;
TeleportToExit (other);
}
void OnTriggerExit2D ( )
{
if (exit == last)
last = null;
}
void TeleportToExit ( Collider2D other )
{
last = transform;
other.transform.position = exit.transform.position;
}
}
y este otro script para controlar que solo se teleporte al apretar un boton:
[and this other script to control only teleport by pressing a button:]
void Update () { if(Input.GetMouseButtonDown(0)){ collider2D.enabled = true; } else{ collider2D.enabled=false; }
}
Lo que yo quiero es que ademas de teleportarse cambie de sprite al llegar al lugar de destino. Tengo el siguiente script para que cambie de sprite al apretar un boton pero no consigo conectar el teleportarse con el cambiar de sprite.
[What I mean is that besides teleport sprite change upon arrival at destination. I have the following script to change sprite when pressing a button but I can not connect to the switch teleport sprite.]
public Sprite energia;
public Sprite rojo;
// Use this for initialization
void SetSprite () {
gameObject.GetComponent<SpriteRenderer> ().sprite = rojo;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)){
SetSprite ();
}
}
¿Alguna sugerencia? Gracias por adelantado.
It's preferred if you write question in English since majority of the crowd here understand it and will be able to help you. I've added the translation (using Google Translate) for now but you can edit it to change if something's is missing.
[Se prefiere si escribes pregunta en Inglés ya que la mayoría de la gente aquí lo entienden y será capaz de ayudarle. He añadido la traducción ( a través de Google Translate) por ahora , pero puedes editarlo para cambiar si algo de falta.]
Questions and Answers have to be in English so other users are able to receive the same help. It's ok to post in another language as long as the English translation is also there.
Hola amigo-un oportunidad a escribir espanol! Que guay!
Soy ingles- excuse my spanish!
No untiliso el 2D mucho, pero pienso que necesitas a 'Instantiate 'el sprite, como eso:
void SetSprite(){
Sprite rojo=Instantiate (rojo, Vector3(0,0,0), Quaternion.identity) as Sprite;
}
Pone su sprite como un Prefab- espero que ayude'!
Popuppirate
La solución mas rápida que se me ocurre es que crees un mensaje desde la clase teleport que llame a la función de setSprite, es decir al apretar el botón de teleport añadir una llamada a