Advertisement
SizilStank

Untitled

Feb 27th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HomingPlayerLaser : MonoBehaviour
  6. {
  7.  
  8.     [SerializeField] private float _speed = 8f;
  9.     [SerializeField] private GameObject _bossHitExplosionAnimPrefab;
  10.  
  11.     public Transform target; // enemyTransform
  12.  
  13.  
  14.     private void Awake()
  15.     {
  16.         if (target != null)
  17.         {
  18.             target = GameObject.FindGameObjectWithTag("Enemy").transform;
  19.         }
  20.        
  21.        
  22.     }
  23.  
  24.     // Update is called once per frame
  25.     void Update()
  26.     {
  27.         if (target == null)
  28.         {
  29.             return;
  30.         }
  31.  
  32.  
  33.  
  34.         if (target != null)
  35.         {
  36.            
  37.             transform.position = Vector3.MoveTowards(transform.position, target.position, _speed * Time.deltaTime);
  38.  
  39.             if (Vector3.Distance(transform.position, target.position) < 0.001f)
  40.             {
  41.                 transform.position = Vector3.MoveTowards(transform.position, target.position, _speed * Time.deltaTime);
  42.             }
  43.         }
  44.  
  45.         if (target.transform.position == null) // This does nothing cant figure out how to make them destroy! They just stick.
  46.         {
  47.             transform.Translate(Vector3.up * 50 * Time.deltaTime);
  48.             Debug.Log("Nothing");
  49.         }
  50.  
  51.  
  52.         if (transform.position.y >= 9.70f || transform.position.y <= -9.70)
  53.         {
  54.             Destroy(this.gameObject);
  55.         }
  56.         if (transform.position.x >= 14.5f || transform.position.x <= -14.5)
  57.         {
  58.             Destroy(this.gameObject);
  59.         }
  60.     }
  61.  
  62.     private void OnTriggerEnter2D(Collider2D other)
  63.     {
  64.         if (other.gameObject.CompareTag("1stBoss"))
  65.         {
  66.             Instantiate(_bossHitExplosionAnimPrefab, transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity);        
  67.         }
  68.  
  69.         if (other.gameObject.CompareTag("BigEnemy"))
  70.         {
  71.             Instantiate(_bossHitExplosionAnimPrefab, transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement