Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- public class Beacon : MonoBehaviour
- {
- AI ai;
- Rigidbody2D myRigidbody2D;
- [SerializeField] float lifetime = 0.25f;
- // Start is called before the first frame update
- void Start()
- {
- myRigidbody2D = GetComponent<Rigidbody2D>();
- ai = FindObjectOfType<AI>();
- StartCoroutine(Kill());
- }
- private void Update()
- {
- if (transform.position.x >= 4.3)
- {
- ai.beaconLocation = transform.position;
- Destroy(gameObject);
- }
- }
- IEnumerator Kill()
- {
- yield return new WaitForSeconds(lifetime);
- SendLocation();
- }
- public void SendLocation()
- {
- if (myRigidbody2D.velocity.x >= 0)
- {
- ai.beaconLocation = transform.position;
- Destroy(gameObject);
- }
- else
- {
- Destroy(gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement