• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nseco · Nov 06, 2014 at 10:31 AM · colliderinputspritegetcomponent

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HarshadK · Nov 06, 2014 at 10:57 AM 0
Share

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.]

avatar image SaraCecilia · Nov 06, 2014 at 12:34 PM 0
Share

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.

avatar image popuppirate · Nov 06, 2014 at 12:59 PM 0
Share

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

avatar image EnriqueL · Nov 06, 2014 at 02:00 PM 0
Share

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Get a script to the object with the press of a button 1 Answer

Trouble accessing scripts (Boo) 1 Answer

Left Click While Holding Right Click 1 Answer

Animation doesn't play on Input 1 Answer

Is it possible to detect which side of a sprite a touch came in from? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges