예제 #1
0
    private void SpawnRoads(Car[] carPrefabs)
    {
        foreach (Road road in roads)
        {
            Vector2Int start = road.Start.position;
            Vector2Int end   = road.End.position;

            CarExit     exit     = realGrid[end.x, end.y].AddComponent <CarExit>();
            CarEntrance entrance = realGrid[start.x, start.y].AddComponent <CarEntrance>();

            entrance.Initialize(road, exit, carPrefabs);
        }
    }
예제 #2
0
    public override void Activate()
    {
        if (vehicleEntrance != null && vehicleEntrance.GetComponent <CarEntrance>() != null && driversID != null)
        {
            // If the driver's collider or one of their additional colliders (necessary to interact with cloth, where applicable) is the collider currently colliding with the vehicle entrance collider,
            // let them enter
            if (driversID.transform.GetComponent <Collider>() == vehicleEntrance.GetComponent <CarEntrance>().GetCurrentCollider() ||
                driversID.additionalColliders.Contains(vehicleEntrance.GetComponent <CarEntrance>().GetCurrentCollider()))
            {
                CarEntrance entrance = vehicleEntrance.GetComponent <CarEntrance>();
                entrance.entering = true;

                if (driversID != null)
                {
                    Transform oper = driversID.transform;

                    oper.transform.position = new Vector3(entrance.transform.position.x, vehicle.position.y - vehicleOriginHeightOffset, entrance.transform.position.z);
                    oper.transform.LookAt(new Vector3(entrance.PositionToFaceWhenEntering.position.x, oper.transform.position.y, entrance.PositionToFaceWhenEntering.position.z));
                    oper.transform.SetParent(vehicle);
                    oper.GetComponent <Rigidbody>().isKinematic = true;
                    oper.GetComponent <Collider>().enabled      = false;
                    if (driversID.additionalColliders.Count > 0)
                    {
                        foreach (Collider col in driversID.additionalColliders)
                        {
                            col.enabled = false;
                        }
                    }
                }

                ParallelActions parActs = new ParallelActions();
                parActs.actions = new List <Action>();

                foreach (Action act in driversID.enterCarActions)
                {
                    parActs.actions.Add(act);
                }

                foreach (Action act in entranceActions)
                {
                    parActs.actions.Add(act);
                }

                actCoord.TriggerParallelActions(parActs);

                bCam.OperateVehicle(this);
            }
        }
    }