// Use this for initialization void Start() { t = transform; cameraT = Camera.main.transform; ai = this.GetComponentInParent <Plane_AI> (); }
public Plane_AI Create() { GameObject go = ObjectFactory.instance.MakeObject(ObjectFactory.PrefabType.Fighter); go.transform.position = new Vector3(transform.position.x + Random.Range(900, 1600), transform.position.y + Random.Range(900, 1600), transform.position.z + Random.Range(900, 1600)); Plane_AI AI = go.GetComponent <Plane_AI> (); AI.Init(_bc); return(AI); }
// Update is called once per frame void FixedUpdate() { RaycastHit hit; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 5000)) { enemyAI = hit.transform.GetComponent <Plane_AI> (); //if enemy is locked-on cone of sight... if (enemyAI != null && prevenemyAI == null) { // ..count time _timeCount += Time.deltaTime; //.. check if time is over locked on time if (_timeCount >= _lockOnTime) { enemyAI.LockedOn(); //..Allow fire missile _allowFire = true; prevenemyAI = enemyAI; } } } else { if (prevenemyAI != null) { _timeOut += Time.deltaTime; if (_timeOut > 1) { StopLockedOn(); _timeOut = 0; } } } //Debug.DrawRay (Camera.main.transform.position, Camera.main.transform.forward * 5000 ,Color.red); if (_allowFire && enemyAI != null) { if (Input.GetKeyDown(KeyCode.F)) { Fire(); } } }
void StopLockedOn() { if (enemyAI != null) { enemyAI.StopLockedOn(); } if (prevenemyAI != null) { prevenemyAI.StopLockedOn(); } _timeCount = 0; _timeOut = 0; _allowFire = false; prevenemyAI = null; enemyAI = null; }
void Start() { timetolockcount = Time.time; flight = this.GetComponent <FlightSystem> (); // get Flight System flight.AutoPilot = true; // set auto pilot to true will make this plane flying and looking to Target automatically timestatetemp = 0; if (!CenterOfBattle) { BattleCenter btcenter = (BattleCenter)GameObject.FindObjectOfType(typeof(BattleCenter)); if (btcenter != null) { CenterOfBattle = btcenter.gameObject.GetComponent <BattleCenter>(); } } chains = this.GetComponentsInChildren <Chaingun> (); plane_ai = this.GetComponent <Plane_AI> (); }