public void SaveGame() { Game g = Game.current = new Game(); Base[] b = GameObject.FindObjectsOfType <Base>(); g.particles = new Particle[b.Length]; for (int i = 0; i < b.Length; i++) { // Creates a BaseObj object for each particle and // sets its position, mass, force, velocity, coefficient of friction. Base bse = b[i]; g.particles[i] = new Particle(bse.Position, bse.Mass, bse.Force, bse.Velocity, bse.gameObject .GetComponentInChildren <Friction>() .Coefficient ); } // Does the same with the planes, except only setting // the position and rotation. PlaneBase[] p = GameObject.FindObjectsOfType <PlaneBase>(); g.planes = new PlaneObj[b.Length]; for (int i = 0; i < p.Length; i++) { PlaneBase pb = p[i]; g.planes[i] = new PlaneObj(pb.Position, pb.Rotation); } // Puts it into the file. SaveLoad.Save(); }
public PlaneBase GetOtherClosestPlane(PlaneBase plane) { List <PlaneBase> newList = new List <PlaneBase>(planes); newList.Remove(plane); PlaneBase closest = newList.OrderBy(t => (t.transform.position - plane.transform.position).sqrMagnitude).FirstOrDefault(); return(closest); }
void OnTriggerEnter2D(Collider2D otherCollider) { PlaneBase plane = otherCollider.gameObject.GetComponent <PlaneBase>(); if (plane != null) { plane.bHit(Power); } Destroy(this.gameObject); }
public void ClearLandingSpot(PlaneBase testPlane) { foreach (ParkingSpot s in parkingSpots) { if (s.plane == testPlane) { s.plane = null; } } }
public PlaneBase GetRandomOtherPlane(PlaneBase plane) { List <PlaneBase> newList = new List <PlaneBase>(planes); newList.Remove(plane); if (newList.Count == 0) { return(null); } return(newList[UnityEngine.Random.Range(0, newList.Count)]); }
public ParkingSpot GetFreeSpot(PlaneBase p) { foreach (ParkingSpot s in parkingSpots) { if (s.plane == null) { s.plane = p; return(s); } } return(null); }
void NextTarget() { if (currentBaseState == BaseState.Moving || currentBaseState == BaseState.Idle) { target = Scr_PlaneHandler.instance.GetRandomEnemyPlane(this); if (target != null && target.currentBaseState != BaseState.Crashing && target.currentBaseState != BaseState.Landed) { SetState(BaseState.Moving); } else { target = null; } } }
public PlaneBase GetRandomEnemyPlane(PlaneBase plane) { List <PlaneBase> newList = new List <PlaneBase>(); foreach (PlaneBase p in planes) { if (p.team != plane.team) { newList.Add(p); } } if (newList.Count == 0) { return(null); } return(newList[UnityEngine.Random.Range(0, newList.Count)]); }
public void LoadGame(int value) { // Destroys all the planes and particles in the current scene. foreach (Selectable obj in FindObjectsOfType <Selectable>()) { Destroy(obj.gameObject); } // Gets the required game. Game game = SaveLoad.savedGames[value]; foreach (Particle p in game.particles) { // Creates a blank particle. GameObject g = GameObject.Instantiate(Resources.Load("Object")) as GameObject; // Gets the base and friction scripts. Base b = g.GetComponent <Base>(); Friction f = g.GetComponentInChildren <Friction>(); // Calls the starting method and sets the // position, coefficient, mass, force, velocity. b.Init(); b.Position = p.position.toVector(); f.Coefficient = p.coefficient; b.Mass = p.mass; b.Force = p.force.toVector(); b.Velocity = p.velocity.toVector(); } // Do the same for all the planes. foreach (PlaneObj plane in game.planes) { GameObject g = GameObject.Instantiate(Resources.Load("Plane")) as GameObject; PlaneBase b = g.GetComponent <PlaneBase>(); b.Rotation = plane.rotation.toVector(); b.Position = plane.position.toVector(); } // Sets the current game to the new game. Game.current = game; }
void Update() { base.UpdateTick(); if (currentBaseState == BaseState.Moving) { if (target != null) { cantReachTargetTimer -= 1 * Time.deltaTime; if (cantReachTargetTimer <= 0) // spent 15 seconds chasing the same target without being able to fire a single bullet, so let's drop it { cantReachTargetTimer = 15f; target = null; SetState(BaseState.Idle); return; } SetTargetPosition(target.transform.position + target.transform.forward * 20); if (attackTimer <= 0) { if (Vector3.Angle(transform.forward, target.transform.position - transform.position) < 20) // check that we're facing the target { if (Vector3.Distance(transform.position, target.transform.position) < attackDistance) // and we're close enough //ProjectileHandler.instance.CreateBulletProjectile(transform.position, transform.position + transform.forward, bodyIntegrity, team); { attackTimer = attackTime; cantReachTargetTimer = 15; // we are in range to fire so reset this timer } } } else { attackTimer -= 1 * Time.deltaTime; } } } }