Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class enemyController1 : MonoBehaviour
  6. {
  7. float direction = 1;
  8. float minX, maxX;
  9.  
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. minX = transform.position.x;
  14. maxX = minX + 10;
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. Vector3 currPos = transform.position;
  21.  
  22. if (currPos.x >= maxX)
  23. {
  24. direction = -1;
  25. }
  26. if (currPos.x <= minX)
  27. {
  28. direction = 1;
  29. }
  30. transform.Translate(new Vector3(direction * 5f * Time.deltaTime, 0, 0));
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement