using System.Collections; using System.Collections.Generic; using UnityEngine; public class CentinelMovementController : 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; public Collider2D overlapContent; public float speed = .5f; public GameObject Player; // Use this for initialization void Start () { Player = GameObject.FindGameObjectWithTag("Player"); } // Update is called once per frame void FixedUpdate () { Player = GameObject.FindGameObjectWithTag("Player"); if (overlapContent = Physics2D.OverlapCircle(this.gameObject.transform.position, detectionRadius, playerMask)) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(Player.transform.position.x, Player.transform.position.y +.5f), speed*Time.deltaTime); 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); //Gizmos.DrawLine(this.gameObject.transform.position,backDetector.position); } }