Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyScript : MonoBehaviour
  6. {
  7.     public Rigidbody2D rb;
  8.     public float MovementDistance;
  9.     public float MovementSpeed;
  10.     public float MoveInterval;
  11.     public float Maxpos;
  12.     public float Minpos;
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.         InvokeRepeating("MoveForward", 0f, MoveInterval);
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.      
  23.     }
  24.  
  25.     private void OnCollisionEnter2D(Collision2D col)
  26.     {
  27.         if(col.gameObject.tag == "Player")
  28.         {
  29.             GameManager.instance.DecreaseLives();
  30.         }
  31.     }
  32.  
  33.    
  34.  
  35.      void MoveForward()
  36.     {
  37.        
  38.         print("working");
  39.         rb.velocity = transform.right * MovementDistance;
  40.         float Xpos = Mathf.Clamp(transform.position.x, Maxpos, Minpos);
  41.         transform.position = new Vector3(Xpos, transform.position.y, transform.position.z);
  42.         transform.Rotate(new Vector3(0f, 0f, 180f));
  43.         print("has turned");
  44.  
  45.     }
  46.  
  47.    
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement