Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [CreateAssetMenu(fileName = "Ability", menuName = "Ability", order = 1)]
  6. public class Ability : ScriptableObject {
  7.  
  8. [SerializeField] private float vitesseHorizontal = 0.0f;
  9. [SerializeField] private float vitesseVertical = 0.0f;
  10. private int directionHorizontal = 1;
  11. private int directionVertical = 1;
  12.  
  13. public void Bouger(Transform ballTransform)
  14. {
  15. Vector3 ballPosition = new Vector3();
  16. ballPosition = ballTransform.position;
  17. ballPosition.x += (vitesseHorizontal * directionHorizontal);
  18.  
  19. if (ballPosition.x > 5)
  20. {
  21. directionHorizontal *= -1;
  22. ballPosition.x = 5.0f;
  23. }
  24. else if(ballPosition.x < -5)
  25. {
  26. directionHorizontal *= -1;
  27. ballPosition.x = -5.0f;
  28. }
  29.  
  30. ballPosition.y += (vitesseVertical * directionVertical);
  31.  
  32. if (ballPosition.y > 5)
  33. {
  34. directionVertical *= -1;
  35. ballPosition.y = 5.0f;
  36. }
  37. else if (ballPosition.y < -5)
  38. {
  39. directionVertical *= -1;
  40. ballPosition.y = -5.0f;
  41.  
  42. }
  43.  
  44. ballTransform.position = ballPosition;
  45.  
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement