コード例 #1
0
    private void goToOtherRooms()
    {
        RoomScript current = roomData.currentRoomScript;

        if (roomData.hasParent)
        {
            float chance = Mathf.Pow(1.0f - current.chanceToLeaveRoom, Time.deltaTime);
            float rand   = Random.Range(0.0f, 1.0f);

            if (rand > chance)
            {
                transform.position = roomData.perviousPosition;
                roomData           = roomData.parentData;
            }
        }

        foreach (RoomScript rs in roomData.currentRoomScript.RoomsToGo)
        {
            float chance = Mathf.Pow(1.0f - rs.chanceToEnterRoom, Time.deltaTime);
            float rand   = Random.Range(0.0f, 1.0f);

            if (rand > chance)
            {
                Transform space         = SimulationManager.getRandomSpaceOfRoom(rs);
                float     halfPS        = 0.5f * SM.personScale;
                float     xScale        = (space.lossyScale.x / 2.0f) - halfPS;
                float     yScale        = (space.lossyScale.y / 2.0f) - halfPS;
                Vector2   xSpawnBorders = new Vector2(space.position.x - xScale, space.position.x + xScale);
                Vector2   ySpawnBorders = new Vector2(space.position.y - yScale, space.position.y + yScale);
                Vector3   pos           = new Vector3(Random.Range(xSpawnBorders.x, xSpawnBorders.y), Random.Range(ySpawnBorders.x, ySpawnBorders.y), 0f);

                PlayerInRoomData PIRD = new PlayerInRoomData();
                PIRD.currentRoomScript = rs;
                PIRD.hasParent         = true;
                PIRD.parentData        = roomData;
                PIRD.perviousPosition  = transform.position;

                transform.position = pos;
                roomData           = PIRD;

                break;
            }
        }
    }
コード例 #2
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.layer == 10) // Layer 10: PersonInfectionSpace
     {
         if (state != PersonState.Susceptible)
         {
             return;
         }
         infectedPeopleNear++;
     }
     else if (other.gameObject.layer == 11) // Layer 11: Room Space
     {
         if (roomData == null)
         {
             roomData = new PlayerInRoomData();
             roomData.currentRoomScript = other.transform.parent.parent.GetComponent <RoomScript>();
         }
     }
 }