public void InteractableInitialize() { //In case I forget... gameObject.layer = LayerMask.NameToLayer("Interactable"); if (GetComponent <PowerCube>() != null) { pc = GetComponent <PowerCube>(); it = InteractableType.PowerCube; } else if (GetComponent <PowerStation>() != null) { ps = GetComponent <PowerStation>(); it = InteractableType.PowerStation; } else if (GetComponent <DoorButton>() != null) { db = GetComponent <DoorButton>(); it = InteractableType.DoorButton; } else if (GetComponent <TimedDoorButton>() != null) { timd = GetComponent <TimedDoorButton>(); it = InteractableType.TimedDoorButton; } else { it = InteractableType.None; } //If universal functionality is needed, that will go here }
public override void perform(GameObject instigator, Trigger trig) { Inventory inventory = instigator.GetComponent <Inventory>(); Debug.Log("recharging "); if (inventory != null) { List <RechargableItem> items = inventory.getItemsExtending <RechargableItem>(); PowerStation station = parent.GetComponent <PowerStation>(); List <RechargableItem> toRecharge = new List <RechargableItem>(); foreach (RechargableItem item in items) { if (!item.isCharged()) { toRecharge.Add(item); } } if (station != null) { station.rechargeItems(toRecharge, instigator); } } }
public Auction(Bid startingBig, PowerStation powerStation) { State = AuctionState.Started; Bids = new List <Bid>(); PowerStation = powerStation; CurrentBid = startingBig; }
//This is called by the plan when we have arrived at a charging spot public void Recharge(PowerStation s) { //Start 'animations' StartCoroutine("MoveToWaypoint", s.GetWaypoint()); StartCoroutine("FaceObject", s.transform); GoToState(CarState.charging); }
void RayCastRight() { RaycastHit2D hit = Physics2D.Raycast(transform.position + ((Vector3.right * vDirection) / 2), Vector2.right * vDirection, 1); if (hit.collider) { if (hit.transform.gameObject.tag != "") { Debug.Log("Hit a " + hit.transform.gameObject.tag); } if (hit.transform.gameObject.tag == "Door") { Door hitDoor = hit.transform.GetComponent <Door>(); if (hitDoor) { hitDoor.activated = true; //energy -= 10; ChangeEnergyValue(-10); } //Destroy(hit.transform.gameObject); } if (hit.transform.gameObject.tag == "PowerStation") { hitStation = hit.transform.GetComponent <PowerStation>(); if (hitStation) { if (!hitStation.active) { StartCoroutine(ActivatePowerStation()); } } } } }
//Try to get a free station IEnumerator PollForStation(PowerStationRoad p) { while (p.GetEmptyPoweredStation() == null) { yield return(new WaitForSeconds(0.1f)); } PowerStation station = p.GetEmptyPoweredStation(); station.Occupy(); chargingAt = station; controlledCar.GoToState(Car.CarState.driving); }
IEnumerator ActivatePowerStation() { anim.SetTrigger("Arm"); yield return(new WaitForSeconds(.5f)); poweringUp = true; energy = 0; hitStation.DeActivate(); hitStation.GetComponent <BoxCollider2D>().enabled = false; hitStation = null; StartCoroutine(EndGame()); }
//Find the closes powerstation that actually has power and returns the road it's on, otherwise null is returned public PowerStationRoad FindNearestPoweredPowerstation(Vector2 position) { float leastDistance = Mathf.Infinity; PowerStation closest = null; foreach (PowerStation p in powerStations) { float thisdist = position.Distance(p.transform.position.ToVector2()); //Do not return unpowered stations if (thisdist < leastDistance && p.Powered) { leastDistance = thisdist; closest = p; } } if (closest == null) { return(null); } return((PowerStationRoad)closest.road); }
private void Start() { Score = 0; station = GameObject.FindGameObjectWithTag("PowerStation").GetComponent <PowerStation>(); }
void EndActiveTrip() { ActiveTrip.completed = true; TripInProgress = false; controlledCar.GoToState(Car.CarState.waiting); switch (ActiveTrip.type) { case Trip.TripType.Park: { ParkingSpace s = ((ParkingSpotRoad)ActiveTrip.end).GetEmptySpace(); //Reserve the parking space s.Occupy(); parkedAt = s; state = State.parked; controlledCar.Park(s); break; } case Trip.TripType.Charge: { PowerStationRoad s = world.FindNearestPoweredPowerstation(controlledCar.transform.position.ToVector2()); if (s == null) { Debug.LogError("No power stations! Handle that."); } PowerStation ps = s.GetEmptyPoweredStation(); //no empty station available //this is actually obsolete. if (ps == null) { Debug.LogError("All stations full (handled in coroutine.)!"); } else { chargingAt = ps; ps.Occupy(); } charging = true; state = State.charging; controlledCar.Recharge(chargingAt); return; } case Trip.TripType.Cruise: { state = State.enRoute; break; } } //Create next journey CreateJourney(); if (ActiveTrip == null) { Finished = true; Game.Instance.OnCarFinished(controlledCar); return; } SetWakeUp(ActiveTrip.departure); }