Ejemplo n.º 1
0
    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;
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        driving  = GetComponentInParent <DrivingScript>();
        material = GetComponent <SpriteRenderer>().material;

        setLights(startOn);
    }
Ejemplo n.º 3
0
    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>();
    }
Ejemplo n.º 4
0
    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);
    }
Ejemplo n.º 5
0
    void Awake()
    {
        heightDistance = Vector3.back * height;

        DrivingScript[] cars      = Component.FindObjectsOfType <DrivingScript>();
        DrivingScript   playerCar = Array.Find <DrivingScript>(cars, c => c.playerControlled);

        if (playerCar)
        {
            SetPlayerCar(playerCar);
        }
    }
Ejemplo n.º 6
0
    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;
    }
Ejemplo n.º 7
0
    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);
    }
Ejemplo n.º 8
0
    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);
        }
    }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
 public void SetPlayerCar(DrivingScript playerCar)
 {
     target             = playerCar.transform;
     transform.position = target.position + heightDistance;
     lastTargetPosition = target.position;
 }
Ejemplo n.º 11
0
 public void SetPlayerCar(DrivingScript car)
 {
     playerCar = car;
 }
Ejemplo n.º 12
0
 // Use this for initialization
 void Start()
 {
     _drivingScript = GetComponent <DrivingScript>();
 }
Ejemplo n.º 13
0
 // Use this for initialization
 void Start()
 {
     _drivingScript      = GetComponent <DrivingScript>();
     _audioSource        = GetComponent <AudioSource>();
     _increasedLoadSpeed = _loadSpeed;
 }
Ejemplo n.º 14
0
 public void SetPlayerCar(DrivingScript playerCar)
 {
     car = playerCar.transform;
     transform.position = car.position + distanceVector;
     lastCarPosition    = car.position;
 }