void SpawnCars(BoundsInt outerBoundsInt) { TileBase[] tiles = traffic.GetTilesBlock(outerBoundsInt); int marginWidth = maxSpawnMargin - minSpawnMargin; int farMarginX = outerBoundsInt.size.x - marginWidth; int farMarginY = outerBoundsInt.size.y - marginWidth; int carCount = Physics2D.OverlapAreaAll( (Vector3)outerBoundsInt.min, (Vector3)outerBoundsInt.max, layerMask).Length; foreach (int y in Enumerable.Range(0, outerBoundsInt.size.y).OrderBy(y => Random.value)) { foreach (int x in Enumerable.Range(0, outerBoundsInt.size.x).OrderBy(x => Random.value)) { // Only use tiles that are within the margin but not visible to the camera. if (carCount < targetCarCount && (x < marginWidth || y < marginWidth || x >= farMarginX || y >= farMarginY)) { TileBase tile = tiles[y * outerBoundsInt.size.x + x]; Vector3 point = traffic.CellToWorld( new Vector3Int(outerBoundsInt.xMin + x, outerBoundsInt.yMin + y, 0)) + halfCell; int dir = tile == null ? -1 : dirs.IndexOf(tile.name); if (dir > -1 && Physics2D.OverlapCircle(point, clearRadius, layerMask) == null) { DrivingScript car = carPrefabs[Random.Range(0, carPrefabs.Length)]; Instantiate(car, point + new Vector3(0, 0, car.transform.position.z), Quaternion.Euler(0, 0, 90 * dir), transform); carCount += 1; } } } } }
void Start() { driving = GetComponentInParent <DrivingScript>(); material = GetComponent <SpriteRenderer>().material; setLights(startOn); }
public static void RegisterObjectReferences(Scene scene, LoadSceneMode lsm) { playerOne = GameObject.FindGameObjectWithTag("PlayerOne"); playerTwo = GameObject.FindGameObjectWithTag("PlayerTwo"); //spawnPointScript = GameObject.FindGameObjectWithTag("Enemy Spawner").GetComponent<spawnPointFollowers>(); Van = GameObject.FindGameObjectWithTag("Van").GetComponentInChildren <DrivingScript>(); }
void SpawnPlayer() { DrivingScript carPrefab = carPrefabs[Random.Range(0, carPrefabs.Length)]; playerCar = Instantiate(carPrefab, transform.position + new Vector3(0, 0, carPrefab.transform.position.z), transform.rotation); playerCar.playerControlled = true; FindObjectOfType <CameraFollowScript>().SetPlayerCar(playerCar); }
void Awake() { heightDistance = Vector3.back * height; DrivingScript[] cars = Component.FindObjectsOfType <DrivingScript>(); DrivingScript playerCar = Array.Find <DrivingScript>(cars, c => c.playerControlled); if (playerCar) { SetPlayerCar(playerCar); } }
void Awake() { DrivingScript[] cars = Component.FindObjectsOfType <DrivingScript>(); DrivingScript playerCar = Array.Find <DrivingScript>(cars, c => c.playerControlled); if (playerCar) { SetPlayerCar(playerCar); } captureCamera = GetComponent <Camera>(); initialSize = captureCamera.orthographicSize; distanceVector = Vector3.forward * transform.position.z; }
void Awake() { ConfigScript config = (ConfigScript)Object.FindObjectOfType(typeof(ConfigScript)); traffic = GameObject.Find("Traffic").GetComponent <Tilemap>(); driving = GetComponent <DrivingScript>(); body = GetComponent <Rigidbody2D>(); carMask = LayerMask.GetMask("Cars"); frontDist = GetComponent <BoxCollider2D>().size.y / 2 + 0.1f; // front of car frontAxleDist = driving.frontWheelOffset.localPosition.y / config.pixelsPerUnit; // front wheels Vector3 frontAxle = transform.position + transform.up * frontAxleDist; Vector3 cellCenter = traffic.CellToLocalInterpolated(traffic.WorldToCell(frontAxle) + new Vector3(0.5f, 0.5f, 0)); goal = GetNextCell(cellCenter); }
void Start() { ConfigScript config = (ConfigScript)Object.FindObjectOfType(typeof(ConfigScript)); ppu = config.pixelsPerUnit; driving = GetComponent <DrivingScript>(); headlights = new GameObject[] { AddHeadlight(true), AddHeadlight(false), }; foreach (GameObject light in headlights) { light.SetActive(startOn); } }
void Start() { if (player1stats == null) { player1stats = new PlayerStats(0, 0, 0, 0, 0, 0, 0, 0, 0); player2stats = new PlayerStats(0, 0, 0, 0, 0, 0, 0, 0, 0); } if (GameObject.FindGameObjectsWithTag("GameManager").Length >= 2) { Destroy(gameObject); } if (SceneManager.GetActiveScene().name.Equals("SampleScene")) { //Editor Only Executions cam = GameObject.FindGameObjectWithTag("MainCamera"); playerOne = GameObject.FindGameObjectWithTag("PlayerOne"); playerTwo = GameObject.FindGameObjectWithTag("PlayerTwo"); Van = GameObject.FindGameObjectWithTag("Van").GetComponentInChildren <DrivingScript>(); GoToLevel(Level.Level1); } DontDestroyOnLoad(this); }
public void SetPlayerCar(DrivingScript playerCar) { target = playerCar.transform; transform.position = target.position + heightDistance; lastTargetPosition = target.position; }
public void SetPlayerCar(DrivingScript car) { playerCar = car; }
// Use this for initialization void Start() { _drivingScript = GetComponent <DrivingScript>(); }
// Use this for initialization void Start() { _drivingScript = GetComponent <DrivingScript>(); _audioSource = GetComponent <AudioSource>(); _increasedLoadSpeed = _loadSpeed; }
public void SetPlayerCar(DrivingScript playerCar) { car = playerCar.transform; transform.position = car.position + distanceVector; lastCarPosition = car.position; }