// Use this for initialization public virtual void OnSpawn() { coll = GetComponent <Collider2D> (); rbody = GetComponent <Rigidbody2D> (); vGen = transform.GetComponentInParent <VehicleGeneration> (); startPos = transform.localPosition; }
//Movement function virtual protected void Movement() { actualMovementSpeed = ((overrideSpeed >= 0) ? overrideSpeed : movementSpeed) * (1f - ((float)timesTapped / (float)tapsRequired)); bool aheadStopped = false; float distAhead = Mathf.NegativeInfinity; float minDist = Mathf.NegativeInfinity; if (aheadOfMe != null) { minDist = stopDistance + VehicleGeneration.BoundaryGetter(this.gameObject) + VehicleGeneration.BoundaryGetter(aheadOfMe.gameObject); distAhead = Vector2.Distance(gameObject.transform.position, aheadOfMe.transform.position); aheadStopped = (aheadOfMe.actualStopped && distAhead <= minDist); } actualStopped = aheadStopped || stopped; if (actualStopped) { rbody.velocity = Vector2.zero; } else { if (aheadOfMe != null) { if (distAhead <= minDist && aheadOfMe.actualMovementSpeed < actualMovementSpeed) { actualMovementSpeed = aheadOfMe.actualMovementSpeed; } } rbody.velocity = Vector2.right * actualMovementSpeed * Mathf.Sign(transform.parent.localScale.x); } }
public void PreventSpawn() //add roadblock to block all lanes on screen for 10 seconds { if (!StaticItems.Paused) { if (StaticItems.BarricadeCount > 0) { StaticItems.BarricadeCount--; GameObject[] roads = GameObject.FindGameObjectsWithTag("RoadSegment"); foreach (GameObject g in roads) { VehicleGeneration v = g.GetComponent <VehicleGeneration> (); v.canSpawn = false; foreach (B4T.Vehicles.VehicleController vc in v.SpawnedVehicles) { Destroy(vc.gameObject); } } } } }
public AutoparkInfoService() { _generator = new VehicleGeneration(); }