Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TransformDemo : MonoBehaviour
  6. {
  7. bool positive = true;
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11.  
  12.  
  13. }
  14.  
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. float d = 1 * Time.deltaTime;
  19. Vector3 pos = transform.position;
  20. //Vector3 posNegative = transform.position;
  21. if (positive == true)
  22. {
  23. if(pos.x<1)
  24. pos.x += d;
  25. transform.position = pos;
  26. if (pos.x >= 1)
  27. {
  28. positive = false;
  29. }
  30. }
  31. if (positive == false)
  32. {
  33. pos.x -= d;
  34. transform.position = pos;
  35. if (pos.x <= -1)
  36. {
  37. positive = true;
  38. }
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement