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 HomingPlayerLaser : MonoBehaviour
- {
- [SerializeField] private float _speed = 8f;
- [SerializeField] private GameObject _bossHitExplosionAnimPrefab;
- public Transform target; // enemyTransform
- private void Awake()
- {
- if (target != null)
- {
- target = GameObject.FindGameObjectWithTag("Enemy").transform;
- }
- }
- // Update is called once per frame
- void Update()
- {
- if (target == null)
- {
- return;
- }
- if (target != null)
- {
- transform.position = Vector3.MoveTowards(transform.position, target.position, _speed * Time.deltaTime);
- if (Vector3.Distance(transform.position, target.position) < 0.001f)
- {
- transform.position = Vector3.MoveTowards(transform.position, target.position, _speed * Time.deltaTime);
- }
- }
- if (target.transform.position == null) // This does nothing cant figure out how to make them destroy! They just stick.
- {
- transform.Translate(Vector3.up * 50 * Time.deltaTime);
- Debug.Log("Nothing");
- }
- if (transform.position.y >= 9.70f || transform.position.y <= -9.70)
- {
- Destroy(this.gameObject);
- }
- if (transform.position.x >= 14.5f || transform.position.x <= -14.5)
- {
- Destroy(this.gameObject);
- }
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (other.gameObject.CompareTag("1stBoss"))
- {
- Instantiate(_bossHitExplosionAnimPrefab, transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity);
- }
- if (other.gameObject.CompareTag("BigEnemy"))
- {
- Instantiate(_bossHitExplosionAnimPrefab, transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement