Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 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. bool negative = true;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12.  
  13.  
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. float d = 1 * Time.deltaTime;
  20. Vector3 pos = transform.position;
  21. //Vector3 posNegative = transform.position;
  22. if (positive == true)
  23. {
  24. if(pos.x<1)
  25. pos.x += d;
  26. transform.position = pos;
  27. if (pos.x >= 1)
  28. {
  29. positive = false;
  30. }
  31. }
  32. if (positive == false)
  33. {
  34. pos.x -= d;
  35. transform.position = pos;
  36. if (pos.x <= -1)
  37. {
  38. positive = true;
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement