using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy_Frog : MonoBehaviour { public bool canMove; Transform PL; Rigidbody2D RB; Animator Ani; public LayerMask G; public GameObject Tung; GameObject Tunge; LineRenderer LR; private void Start() { RB = transform.GetComponent(); Ani = transform.GetComponent(); LR = transform.GetComponent(); canMove = true; } private void Update() { if(Tunge != null) { LR.positionCount = 2; LR.SetPosition(0, transform.position); LR.SetPosition(1, Tunge.transform.position); } else { LR.positionCount = 0; } if (!canMove) { return; } if (PL == null) { FindPlayer(); } else { GotPlayer(); } } private void FindPlayer() { if(Physics2D.OverlapCircle(transform.position, 50f, G)) { PL = Physics2D.OverlapCircle(transform.position, 50f, G).transform; } } private void GotPlayer() { if (!Physics2D.OverlapCircle(transform.position, 50f, G)) { PL = null; return; } if (Vector2.Distance(transform.position, PL.position) >= 20) { JumpToPlayer(); return; } Attack(); } private void Attack() { Ani.Play("Frog_Shoot"); canMove = false; } private void JumpToPlayer() { RB.AddForce(new Vector2((PL.position - transform.position).normalized.x * 10, 10)); Ani.Play("Frog_Shoot"); canMove = false; } public void shoot() { Tunge = GameObject.Instantiate(Tung, transform.position, Quaternion.AngleAxis((Mathf.Atan2((transform.position.y - PL.position.y), (transform.position.x - PL.position.x)) * Mathf.Rad2Deg) + 180, Vector3.forward)); Tunge.GetComponent().setDmg = 5; Tunge.GetComponent().OwnTag = transform.tag; } }