using System.Collections; using System.Collections.Generic; using UnityEngine; public class TurretController : MonoBehaviour { public float detectionRadius = 0.5f; public LayerMask playerMask; public GameObject missile; public GameObject missileShooted; public float shootSpeed = .5f; public Transform shootPoint; public float coolDown = 1 ; public float actualTime = 1; // Use this for initialization void Start () { } // Update is called once per frame void Update () { Search(); } void Search() { if (Physics2D.OverlapCircle(this.gameObject.transform.position, detectionRadius, playerMask) ) { if (actualTime >= coolDown) { missileShooted = Instantiate(missile, new Vector2(shootPoint.position.x, shootPoint.position.y), this.transform.rotation); missileShooted.GetComponent().velocity = transform.TransformDirection(Vector2.right * Time.deltaTime * shootSpeed * 100 * (1 / Time.timeScale)); actualTime = 0; } } Recharge(); } void Recharge() { if (actualTime <= coolDown) { actualTime = actualTime + Time.deltaTime; } } private void OnDrawGizmos() { Gizmos.DrawWireSphere(this.gameObject.transform.position,detectionRadius); } }