Guest User

Untitled

a guest
Oct 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public class MoveRightLeft : MonoBehaviour {
  2. float posX;
  3. float posY;
  4. float speed = 0.1f;
  5. int direction = 1;
  6.  
  7. // Use this for initialization
  8. void Start () {
  9. posX = transform.position.x;
  10. posY = transform.position.y;
  11. }
  12.  
  13. // Update is called once per frame
  14. void Update ()
  15. {
  16. transform.position = new Vector3 (posX, posY, 0);
  17. posX += speed * direction;
  18. // if (posX > 7f) {
  19. // direction = -1;
  20. // } else if (posX < -7f) {
  21. // direction = 1;
  22. // }
  23. //
  24. if (posX > 7f || posX < -7f) {
  25. direction *= -1;
  26. }
  27. }
Add Comment
Please, Sign In to add comment