Advertisement
SizilStank

Untitled

Nov 8th, 2022
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MovementTest : MonoBehaviour //This is what controls the Centa and is on the EnemyA1 and EnemyA2 GameObject
  6. {
  7.  
  8.     [SerializeField][Range(-10, 10)] float moveSpeed = 1f;
  9.     [SerializeField] [Range(0, 5)] float speed = 1f;
  10.     [SerializeField] [Range(-10, 10)] float range = 1f;
  11.     [SerializeField] [Range(-10, 10)] float rangeMotion = 1f;
  12.     [SerializeField]  float counter = 0;
  13.     [SerializeField] private Vector3 _leftORright;
  14.     [SerializeField] private Vector3 _startPos;
  15.  
  16.     [SerializeField] private GameObject _spawn;
  17.  
  18.     private void Start()
  19.     {
  20.         _startPos = transform.position;
  21.     }
  22.  
  23.     void Update()
  24.     {
  25.         loop();
  26.         DestroyOnXAxisOnPos();
  27.     }
  28.  
  29.     void loop()
  30.     {
  31.         float yPos = Mathf.PingPong((Time.time + counter) * speed, rangeMotion) * range;
  32.         transform.position = new Vector3(transform.position.x, _startPos.y + yPos, transform.position.z);
  33.         transform.Translate(_leftORright * moveSpeed * Time.unscaledDeltaTime);//!!!!we changed this to unscaled but breaks Pause game
  34.     }
  35.        
  36.     public void SetWaitMotion(int count)
  37.     {
  38.         counter = count * .25f;
  39.     }
  40.  
  41.     private void DestroyOnXAxisOnPos()
  42.     {
  43.         if (transform.position.x > 13)
  44.         {
  45.             Destroy(this.gameObject);
  46.         }
  47.         if (transform.position.x < -13)
  48.         {
  49.             Destroy(this.gameObject);
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement