// check ai shot for injured or die player ship bool CheckAIShipShoot(Vector3 shoot) { // check cubes transform == shoot foreach (Collider cube in playerShipColliders) { Debug.Log("Compare shot " + shoot + " with cube pos " + cube.gameObject.transform.position); if (cube.transform.position.x == shoot.x && cube.transform.position.z == shoot.z) { Debug.Log("AI shoot in " + cube.transform.parent.name); aSource.PlayOneShot(audioManager.ship); var ship = playerFieldData.Ships.Find(x => x.go == cube.transform.parent.gameObject); ship.status = PlayerField.shipStatus.Injured; cube.transform.position += new Vector3(0, -0.2f, 0); //DestroyCube(cube.gameObject); if (CheckPlayerShipDie(ship.go.transform)) { ship.status = PlayerField.shipStatus.Die; AddDeadZone(ship.go); playerFieldData.CheckGameStatus(); } else { ship.status = PlayerField.shipStatus.Injured; } return(true); } } return(false); }
// check player fire cell for injured or die ai ship void CheckFireCell(RaycastHit hit) { if (hit.collider.CompareTag("Ship")) { aSource.PlayOneShot(audioManager.ship); GameObject shipInjured = Instantiate(hitShip); shipInjured.transform.position = Vector3Int.RoundToInt(hit.collider.transform.position); shipInjured.transform.SetParent(otherPlayerFeildData.transform); shipInjured.transform.localPosition = Vector3Int.CeilToInt(shipInjured.transform.localPosition); hit.collider.GetComponentInChildren <MeshRenderer>().enabled = true; var ship = otherPlayerFeildData.Ships.Find(x => x.go == hit.collider.transform.parent.gameObject); ship.status = PlayerField.shipStatus.Injured; // check ship status if (CheckShipDie(hit.collider.transform.parent)) { aSource.PlayOneShot(audioManager.ship); hit.collider.transform.parent.position -= new Vector3(0, 0.2f, 0); // set die in playerfield ship.status = PlayerField.shipStatus.Die; Debug.Log("ship " + ship.go.name + " " + ship.status); otherPlayerFeildData.CheckGameStatus(); } } if (hit.collider.CompareTag("Field")) { // check fire in place var checkCell = Vector3Int.RoundToInt(hit.point); if (!CheckFire(checkCell)) { aSource.PlayOneShot(audioManager.empty); GameObject fire = Instantiate(cross); fire.transform.localPosition = checkCell + new Vector3(0, -1f, 0); fire.transform.SetParent(otherPlayerFeildData.transform); fire.transform.localPosition = Vector3Int.CeilToInt(fire.transform.localPosition); } playerCanShot = false; } }