/// <summary> /// Makes the argument objectToMakeUnused marked as unused. This method is generated to be used /// by generated code. Use Destroy instead when writing custom code so that your code will behave /// the same whether your Entity is pooled or not. /// </summary> public static void MakeUnused(CannonProjectile objectToMakeUnused, bool callDestroy) { if (callDestroy) { objectToMakeUnused.Destroy(); } }
public static CannonProjectile CreateNew(Layer layer, float x = 0, float y = 0) { CannonProjectile instance = null; instance = new CannonProjectile(mContentManagerName ?? FlatRedBall.Screens.ScreenManager.CurrentScreen.ContentManagerName, false); instance.AddToManagers(layer); instance.X = x; instance.Y = y; foreach (var list in ListsToAddTo) { if (SortAxis == FlatRedBall.Math.Axis.X && list is PositionedObjectList <CannonProjectile> ) { var index = (list as PositionedObjectList <CannonProjectile>).GetFirstAfter(x, Axis.X, 0, list.Count); list.Insert(index, instance); } else if (SortAxis == FlatRedBall.Math.Axis.Y && list is PositionedObjectList <CannonProjectile> ) { var index = (list as PositionedObjectList <CannonProjectile>).GetFirstAfter(y, Axis.Y, 0, list.Count); list.Insert(index, instance); } else { // Sort Z not supported list.Add(instance); } } if (EntitySpawned != null) { EntitySpawned(instance); } return(instance); }
private static void FactoryInitialize() { const int numberToPreAllocate = 20; for (int i = 0; i < numberToPreAllocate; i++) { CannonProjectile instance = new CannonProjectile(mContentManagerName, false); mPool.AddToPool(instance); } }
private void Shoot() { //5 degrees gap - for inaccurace calculations bool isCannonRotatedToTarget = Vector3.Angle(turretGun.forward, targetingPosition - turretGun.position) <= 5; if (Time.time - lastShotTime >= shootInterval && isCannonRotatedToTarget) { CannonProjectile cannonProjectile = pool.GetNewObjectSilently() as CannonProjectile; cannonProjectile.transform.position = turretGun.position; cannonProjectile.transform.rotation = Quaternion.FromToRotation(projectile.transform.forward, turretGun.forward); lastShotTime = Time.time; } }
private void Shot() { Vector3 cannonDirection = _xRotation.transform.forward.normalized; Vector3 xTargetDirection = TargetSetting().normalized; float dotBetweenCannonAndTarget = Vector3.Dot(cannonDirection, xTargetDirection); if (dotBetweenCannonAndTarget < _dotDirectionDeviation) { return; } GameObject projectile = Instantiate(_projectilePrefab, _shootPoint.position, _xRotation.transform.rotation); CannonProjectile canonProjectile = projectile.GetComponent <CannonProjectile>(); canonProjectile.Shot(TargetSetting(), _ballisticTrajectory); StartCoroutine(ShotInterval()); }
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(currentTankCoordinates.getX(), 1f, currentTankCoordinates.getY())) { cannonFire = redTanks[i]; } } for (int i = 0; i < blueTanks.Length; i++) { if (blueTanks[i].transform.position == new Vector3(currentTankCoordinates.getX(), 1f, currentTankCoordinates.getY())) { cannonFire = blueTanks[i]; } } cannonScript = cannonFire.GetComponent <CannonProjectile>(); if (cannonScript == null) { Debug.Log("CannonProjectile Script is null"); } } for (int i = 1; i <= this.distance; i++) { switch (currentIteration) { case 0: // Check for index out of bounds if (currentTankX + i >= gridSize) { continue; } // Check for mountains if (grid.getGridNode(currentTankX + i, currentTankY).getTerrain() is Mountain) { return(false); } // 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; } // Check for mountains if (grid.getGridNode(currentTankX - i, currentTankY).getTerrain() is Mountain) { return(false); } // 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; } // Check for mountains if (grid.getGridNode(currentTankX, currentTankY + i).getTerrain() is Mountain) { return(false); } // 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; } // Check for mountains if (grid.getGridNode(currentTankX, currentTankY - i).getTerrain() is Mountain) { return(false); } // 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); }
private void Awake() { _projectile = _projectilePrefab.GetComponent <CannonProjectile>(); _enemies = FindObjectOfType <EnemiesData>(); _delayShot = new WaitForSeconds(_shootInterval); }
/// <summary> /// Makes the argument objectToMakeUnused marked as unused. This method is generated to be used /// by generated code. Use Destroy instead when writing custom code so that your code will behave /// the same whether your Entity is pooled or not. /// </summary> public static void MakeUnused(CannonProjectile objectToMakeUnused) { MakeUnused(objectToMakeUnused, true); }
// Use this for initialization void Awake() { myCP = GetComponentInParent <CannonProjectile>(); }