Ejemplo n.º 1
0
    public void CreateSpecificRole(Role newRole)
    {
        if (transform.position.y > 0)
        {
            // Determine start and end positions for pedestrian
            float startY = 2.2f;
            float endY   = -3f;

            // Create pedestrian
            Vector3 streetcarPosition = GameObject.FindGameObjectWithTag("Streetcar").transform.position;
            Vector3 spawnPosition     = new Vector3(streetcarPosition.x + 3, startY, 0);

            GameObject newPedestrian = Instantiate(pedestrianPrefab, spawnPosition, Quaternion.identity) as GameObject;
            newPedestrian.transform.SetParent(pedestrianContainer);

            // Set Role
            Pedestrian pedestrianScript = newPedestrian.GetComponent <Pedestrian> ();
            pedestrianScript.SetRole(newRole);
            pedestrianScript.SetMoveSpeed(1f);
            pedestrianScript.SetMoveDelayTime(1f);

            // Set Sprite
            switch (newRole)
            {
            case Role.Coin:
                newPedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [0];
                break;

            case Role.Stink:
                newPedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)];
                break;

            case Role.Chunky:
                newPedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = chunkySprites [Random.Range(0, chunkySprites.Length)];
                break;

            case Role.Inspector:
                newPedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = inspectorSprites [Random.Range(0, inspectorSprites.Length)];
                break;

            case Role.Dazer:
                newPedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = dazerSprites [Random.Range(0, dazerSprites.Length)];
                break;

            case Role.Officer:
                newPedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = officerSprites [Random.Range(0, officerSprites.Length)];
                break;

            case Role.Raver:
                newPedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)];
                break;
            }

            // Set destination
            Vector3 newDestination = new Vector3(streetcarPosition.x + 3, endY, 0);
            pedestrianScript.SetDestination(newDestination);
        }
    }
Ejemplo n.º 2
0
    void GetNewRole(GameObject pedestrian)
    {
        float      randomValue      = Random.Range(0, raverPercentage + officerPercentage + dazerPercentage + inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage);
        Pedestrian pedestrianScript = pedestrian.GetComponent <Pedestrian>();

        if (randomValue < coinPercentage)
        {
            pedestrianScript.SetRole(Role.Coin);
            pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)];
        }
        else if (randomValue < stinkPercentage + coinPercentage)
        {
            pedestrianScript.SetRole(Role.Stink);
            pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)];
        }
        else if (randomValue < chunkyPercentage + stinkPercentage + coinPercentage)
        {
            pedestrianScript.SetRole(Role.Chunky);
            pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = chunkySprites [Random.Range(0, chunkySprites.Length)];
        }
        else if (randomValue < inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage)
        {
            pedestrianScript.SetRole(Role.Inspector);
            pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = inspectorSprites [Random.Range(0, inspectorSprites.Length)];
        }
        else if (randomValue < dazerPercentage + inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage)
        {
            pedestrianScript.SetRole(Role.Dazer);
            pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = dazerSprites [Random.Range(0, dazerSprites.Length)];
        }
        else if (randomValue < officerPercentage + dazerPercentage + inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage)
        {
            pedestrianScript.SetRole(Role.Officer);
            pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = officerSprites [Random.Range(0, officerSprites.Length)];
        }
        else if (randomValue < raverPercentage + officerPercentage + dazerPercentage + inspectorPercentage + chunkyPercentage + stinkPercentage + coinPercentage)
        {
            pedestrianScript.SetRole(Role.Raver);
        }
        else
        {
            pedestrianScript.SetRole(Role.Norm);
            pedestrian.GetComponentInChildren <SpriteRenderer> ().sprite = pedestrianSprites [Random.Range(0, pedestrianSprites.Length)];
        }

        if (pedestrianScript.GetRole() != Role.Norm)
        {
            pedestrianScript.SetMoveSpeed(2);
        }
    }