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 EnemyScript : MonoBehaviour
- {
- public Rigidbody2D rb;
- public float MovementDistance;
- public float MovementSpeed;
- public float MoveInterval;
- public float Maxpos;
- public float Minpos;
- // Start is called before the first frame update
- void Start()
- {
- InvokeRepeating("MoveForward", 0f, MoveInterval);
- }
- // Update is called once per frame
- void Update()
- {
- }
- private void OnCollisionEnter2D(Collision2D col)
- {
- if(col.gameObject.tag == "Player")
- {
- GameManager.instance.DecreaseLives();
- }
- }
- void MoveForward()
- {
- print("working");
- rb.velocity = transform.right * MovementDistance;
- float Xpos = Mathf.Clamp(transform.position.x, Maxpos, Minpos);
- transform.position = new Vector3(Xpos, transform.position.y, transform.position.z);
- transform.Rotate(new Vector3(0f, 0f, 180f));
- print("has turned");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement