public static void destroyProjectile(MortarProjectile projectile) { if (projectile) { projectile.destroySelf(); } }
void Shoot() { GameObject projectiletGO = (GameObject)Instantiate(projectile_prefab, spawn_point.position, spawn_point.rotation); MortarProjectile bullet_script = projectiletGO.GetComponent <MortarProjectile>(); if (bullet_script != null) { bullet_script.SetDestination(target); firing = true; current_move_timer = barrel_move_timer; } }
private IEnumerator checkCollisionRoutine() { while (m_shieldActive) { // Destroy any projectiles we are colliding with List <MortarProjectile> blockedProjectiles = new List <MortarProjectile>(); if (MortarProjectile.getProjectilesInRadius(transform.position, m_shieldRadius, ref blockedProjectiles)) { foreach (MortarProjectile projectile in blockedProjectiles) { MortarProjectile.destroyProjectile(projectile); } } yield return(new WaitForSeconds(m_tickRate)); } }
[SerializeField] private Transform m_shootFrom; // Transform which we shoot from // TowerScript Interface protected override void performAction(MonsterBase target) { if (!target) { Debug.LogError("MortarTurret script is expecting target to be valid"); return; } if (string.IsNullOrEmpty(m_projectilePrefab)) { return; } Transform spawnTransform = m_shootFrom ? m_shootFrom : transform; // Direction to shoot Vector2 dir = (target.transform.position - m_shootFrom.position).normalized; float shootDir = Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x); // Since game is 2D, we only need one axis of rotation object[] spawnData = new object[2]; spawnData[0] = GameManager.manager.getPlayerIdFromBoard(Board); spawnData[1] = shootDir; GameObject projectileObject = PhotonNetwork.Instantiate(m_projectilePrefab, m_shootFrom.position, Quaternion.identity, 0, spawnData); if (!projectileObject) { return; } MortarProjectile projectile = projectileObject.GetComponent <MortarProjectile>(); Assert.IsNotNull(projectile); projectile.initProjectile(m_tower.Board, this); }
private bool attackCheck(Grid grid, int currentIteration, CoordinateSet currentTankCoordinates, GridNode targetNode, bool updateState) { int gridSize = grid.getGridSize(); int currentTankX = currentTankCoordinates.getX(); int currentTankY = currentTankCoordinates.getY(); int targetNodeX = targetNode.getCoordinateSet().getX(); int targetNodeY = targetNode.getCoordinateSet().getY(); if (updateState) { redTanks = GameObject.FindGameObjectsWithTag("Red Tank"); blueTanks = GameObject.FindGameObjectsWithTag("Blue Tank"); for (int i = 0; i < redTanks.Length; i++) { if (redTanks[i].transform.position == new Vector3(currentTankX, .8f, currentTankY)) { mortarFire = redTanks[i]; } } for (int i = 0; i < blueTanks.Length; i++) { if (blueTanks[i].transform.position == new Vector3(currentTankX, .8f, currentTankY)) { mortarFire = blueTanks[i]; } } mortarScript = mortarFire.GetComponent <MortarProjectile>(); if (mortarScript == null) { Debug.Log("MortarProjectile Script is null"); } mortarScript.setStart(currentTankX, currentTankY); mortarScript.setEnd(targetNodeX, targetNodeY); } for (int i = 1; i <= this.distance; i++) { switch (currentIteration) { case 0: // Check for index out of bounds if (currentTankX + i >= gridSize) { continue; } // Do final check to see if this is the target node if ((currentTankX + i) == targetNodeX && currentTankY == targetNodeY) { orientation = Orientations.Right; return(true); } break; case 1: // Check for index out of bounds if (currentTankX - i < 0) { continue; } // Do final check to see if this is the target node if ((currentTankX - i) == targetNodeX && currentTankY == targetNodeY) { orientation = Orientations.Left; return(true); } break; case 2: // Check for index out of bounds if (currentTankY + i >= gridSize) { continue; } // Do final check to see if this is the target node if ((currentTankX) == targetNodeX && (currentTankY + i) == targetNodeY) { orientation = Orientations.Up; return(true); } break; case 3: // Check for index out of bounds if (currentTankY - i < 0) { continue; } // Do final check to see if this is the target node if ((currentTankX) == targetNodeX && (currentTankY - i) == targetNodeY) { orientation = Orientations.Down; return(true); } break; } } return(false); }