using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class FatassController : MonoBehaviour { public float detectionRadius = 0.5f; public LayerMask playerMask; public GameObject missile; public GameObject missileShooted; public GameObject missile1; public GameObject missileShooted1; public GameObject missile2; public GameObject missileShooted2; public float shootSpeed = .5f; public Transform shootPoint; public float coolDown = 1; public float actualTime = 1; public Collider2D overlapContent; public float speed = .5f; public float AproachDistance = .5f; public Transform backDetector; public float direction = 180; public int isRigt = 1; // Use this for initialization void Start() { } // Update is called once per frame void FixedUpdate() { Search(); } void Search() { if (Physics2D.Linecast(this.gameObject.transform.position, backDetector.position, playerMask)) { isRigt = isRigt * -1; } if (isRigt == -1) { transform.rotation = new Quaternion(0, 180, 0, 0); } else if (isRigt == 1) { transform.rotation = new Quaternion(0, 0, 0, 0); } if (overlapContent = Physics2D.OverlapCircle(this.gameObject.transform.position, detectionRadius, playerMask)) { if (Vector2.Distance(overlapContent.transform.position, this.gameObject.transform.position) > AproachDistance) { transform.Translate(new Vector2(1, 0) * Time.deltaTime * -speed); }else { actualTime = 1; } if (actualTime >= coolDown) { missileShooted = Instantiate(missile, new Vector2(shootPoint.position.x, shootPoint.position.y), this.transform.rotation); missileShooted1 = Instantiate(missile1, new Vector2(shootPoint.position.x + 0.2f, shootPoint.position.y + .2f), this.transform.rotation); missileShooted1.GetComponent().velocity = transform.TransformDirection(Vector2.up * Time.deltaTime * (shootSpeed + 2) * UnityEngine.Random.Range(100, 200.0f) * (1 / Time.timeScale)); missileShooted2 = Instantiate(missile2, new Vector2(shootPoint.position.x - 0.2f, shootPoint.position.y+ .2f), this.transform.rotation); missileShooted2.GetComponent().velocity = transform.TransformDirection(Vector2.up * Time.deltaTime * (shootSpeed + 4) * UnityEngine.Random.Range(100, 200.0f) * (1 / Time.timeScale)); overlapContent.gameObject.GetComponent().health -= 50; Destroy(this.gameObject); actualTime = 0; } } //Recharge(); } void Recharge() { if (actualTime <= coolDown) { actualTime = actualTime + Time.deltaTime; } } private void OnDrawGizmos() { Gizmos.DrawWireSphere(this.gameObject.transform.position, detectionRadius); //Gizmos.DrawLine(this.gameObject.transform.position,backDetector.position); } }