Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MovimentoFantasma : MonoBehaviour {
  6. // Use this for initialization
  7. public bool flag = true;
  8. public int cont = 0;
  9. public Vector3 posicao_Atual;
  10. public Vector3 posicao_Inicial;
  11. public Transform personagem_Transform;
  12. public SpriteRenderer personagem_SpriteRenderer;
  13. void Start () {
  14. this.personagem_Transform = gameObject.GetComponent<Transform>();
  15. this.personagem_SpriteRenderer = gameObject.GetComponent<SpriteRenderer>();
  16. float x_Inicial = personagem_Transform.position.x;
  17. float y_Inicial = personagem_Transform.position.y;
  18. this.posicao_Atual = new Vector3(x_Inicial, y_Inicial, 0);
  19. this.posicao_Inicial = new Vector3(x_Inicial, y_Inicial, 0);
  20. }
  21. void Update () {
  22. movimentarElemento(5,0.1f);
  23. }
  24. public void movimentarElemento(float distancia,float velocidade) {
  25. if (posicao_Atual.x < (posicao_Inicial.x + distancia) && flag == true){
  26. this.posicao_Atual.x += velocidade;
  27. personagem_Transform.position = new Vector3(this.posicao_Atual.x, this.posicao_Atual.y, 0);
  28. this.cont++;
  29. personagem_SpriteRenderer.flipX = false;
  30. }
  31. else{
  32. flag = false;
  33. }
  34. if (posicao_Atual.x > posicao_Inicial.x && flag == false){
  35. this.posicao_Atual.x-= velocidade;
  36. personagem_Transform.position = new Vector3(this.posicao_Atual.x, this.posicao_Atual.y, 0);
  37. this.cont--;
  38. personagem_SpriteRenderer.flipX = true;
  39. }
  40. else{
  41.  
  42. flag = true;
  43. }
  44.  
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement