Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class PlayerMover : MonoBehaviour
  4. {
  5. public GameObject m_player = null;
  6. public float m_heightA = 0f;
  7. public float m_heightB = 3f;
  8. public float m_speed = 1f;
  9.  
  10. public delegate void OnLocationUpdateHandler();
  11. public OnLocationUpdateHandler OnLocationUpdate;
  12.  
  13. private void Awake()
  14. {
  15. OnLocationUpdate = new OnLocationUpdateHandler(TowardsB);
  16. }
  17.  
  18. private void Update()
  19. {
  20. OnLocationUpdate();
  21. }
  22.  
  23. private void TowardsA()
  24. {
  25. Debug.Log("Katt");
  26. Vector3 p = m_player.transform.position;
  27. p.y -= Time.deltaTime * m_speed;
  28. if (p.y < m_heightA)
  29. {
  30. OnLocationUpdate = new OnLocationUpdateHandler(TowardsB);
  31. }
  32. m_player.transform.position = p;
  33. }
  34.  
  35. private void TowardsB()
  36. {
  37. Debug.Log("Hund");
  38. Vector3 p = m_player.transform.position;
  39. p.y += Time.deltaTime * m_speed;
  40. if (p.y > m_heightB)
  41. {
  42. OnLocationUpdate = new OnLocationUpdateHandler(TowardsA);
  43. }
  44. m_player.transform.position = p;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement