Advertisement
SizilStank

Untitled

Dec 31st, 2022
1,296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerLaserSeekEnemy : MonoBehaviour
  6. {
  7.     [SerializeField] private float _laserSpeed = 1f;
  8.     [SerializeField] private float _destroyGameObejectAtYPos = 6.8f;
  9.     [SerializeField] private Transform _seekEnemy;
  10.  
  11.     private void Start()
  12.     {
  13.         _seekEnemy = GameObject.FindGameObjectWithTag("PlayerLaserSeeks").transform;
  14.     }
  15.  
  16.     // Update is called once per frame
  17.     void Update()
  18.     {
  19.  
  20.         if (_seekEnemy != null && !_seekEnemy.Equals(null))
  21.         {          
  22.             float move = _laserSpeed * Time.deltaTime;
  23.             transform.position = Vector3.MoveTowards(transform.position, _seekEnemy.transform.position, move);
  24.             Debug.DrawLine(transform.position, _seekEnemy.position);
  25.         }
  26.  
  27.         if (_seekEnemy == null && _seekEnemy.Equals(null))
  28.         {
  29.             transform.Translate(Vector3.up * _laserSpeed * Time.deltaTime);
  30.         }
  31.  
  32.        
  33.  
  34.         if (transform.position.y >= _destroyGameObejectAtYPos)
  35.         {
  36.             if (transform.parent != null)
  37.             {
  38.                 Destroy(transform.parent.gameObject);
  39.             }
  40.  
  41.             Destroy(this.gameObject);
  42.         }
  43.  
  44.        
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement