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 PlayerLaserSeekEnemy : MonoBehaviour
- {
- [SerializeField] private float _laserSpeed = 1f;
- [SerializeField] private float _destroyGameObejectAtYPos = 6.8f;
- [SerializeField] private Transform _seekEnemy;
- private void Start()
- {
- _seekEnemy = GameObject.FindGameObjectWithTag("PlayerLaserSeeks").transform;
- }
- // Update is called once per frame
- void Update()
- {
- if (_seekEnemy != null && !_seekEnemy.Equals(null))
- {
- float move = _laserSpeed * Time.deltaTime;
- transform.position = Vector3.MoveTowards(transform.position, _seekEnemy.transform.position, move);
- Debug.DrawLine(transform.position, _seekEnemy.position);
- }
- if (_seekEnemy == null && _seekEnemy.Equals(null))
- {
- transform.Translate(Vector3.up * _laserSpeed * Time.deltaTime);
- }
- if (transform.position.y >= _destroyGameObejectAtYPos)
- {
- if (transform.parent != null)
- {
- Destroy(transform.parent.gameObject);
- }
- Destroy(this.gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement