public bool CheckLineOfSight(GameObject alienShip) { //Debug.Log("checking for sight"); // Determine if there is line of sight to the alien ship Vector3 alienShipDirection = alienShip.transform.position - BarrelPivot.transform.position; bool hitEarth = false; AlienShip alienScript = null; RaycastHit[] hits; hits = Physics.RaycastAll(BarrelPivot.transform.position, alienShipDirection, 100f); foreach (RaycastHit hit in hits) { if (hit.transform.tag == "Earth") { hitEarth = true; } if (hit.transform.tag == "Alien") { alienScript = hit.transform.gameObject.GetComponent <AlienShip>(); } } if (!hitEarth) { currentTarget = alienShip; if (alienScript != null && alienScript.TakeDamage()) { FireAt(alienShip.transform.position); } } return(false); }
void OnTriggerEnter(Collider other) { AlienShip alienScript = other.gameObject.GetComponent <AlienShip>(); if (alienScript != null) { Debug.Log("Boom"); alienScript.TakeDamage(200); Destroy(gameObject); } }
void OnTriggerEnter(Collider other) { AlienShip alienScript = other.gameObject.GetComponent <AlienShip>(); if (alienScript != null) { Debug.Log("Boom"); alienScript.TakeDamage((int)damage); // TODO: Replace with Object Pooling Destroy(gameObject); } }