Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class enemyController1 : MonoBehaviour
- {
- float direction = 1;
- float minX, maxX;
- // Start is called before the first frame update
- void Start()
- {
- minX = transform.position.x;
- maxX = minX + 10;
- }
- // Update is called once per frame
- void Update()
- {
- Vector3 currPos = transform.position;
- if (currPos.x >= maxX)
- {
- direction = -1;
- }
- if (currPos.x <= minX)
- {
- direction = 1;
- }
- transform.Translate(new Vector3(direction * 5f * Time.deltaTime, 0, 0));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement