Beispiel #1
0
    void Start()
    {
        foreach (Image i in player1ScoreList)
        {
            i.color = new Color(i.color.r, i.color.g, i.color.b, 30f / 255f);
        }
        foreach (Image i in player2ScoreList)
        {
            i.color = new Color(i.color.r, i.color.g, i.color.b, 30f / 255f);
        }

        LeftRight    = gameObject.AddComponent <AnalogToAxisLayer> ();
        LeftRightAlt = gameObject.AddComponent <AnalogToAxisLayer> ();

        LeftRight.axisName    = PlayerInfoPasser.GetController(0).movement.x.axisName;
        LeftRightAlt.axisName = PlayerInfoPasser.GetController(1).movement.x.axisName;

        victory1Image.color = Color.clear;
        victory2Image.color = Color.clear;
        MessagingManager.AddListener(this);
    }
Beispiel #2
0
    void CreatePlayers()
    {
        Debug.Log("A");

        //get info from player data
        GameObject playerPrefab = characterPrefabs[player0Data.characterID];
        GameObject weaponPrefab = weaponPrefabs[player0Data.weaponID];

        //instantiate player prefab in random position from 0,0

        Vector3 pos = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance);

        while (NavMesh.SamplePosition(pos, out _hit, 0.4f, NavMesh.AllAreas) == false)
        {
            pos = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance);
            Debug.Log("CantSpawnA");
        }

        playerA = (GameObject)GameObject.Instantiate(
            playerPrefab,
            pos,
            Quaternion.identity);
        cameraReference.a = playerA.GetComponentInChildren <RigidBodyTopDownMovement>().gameObject;

        playerA.GetComponent <PlayerInfo> ().controller = PlayerInfoPasser.GetController(0);
        playerA.GetComponent <PlayerInfo>().AssignPlayer(0);

        //instantiate weapon prefab
        GameObject weaponA = (GameObject)GameObject.Instantiate(weaponPrefab, pos, Quaternion.identity);

        playerA.GetComponent <PlayerInfo>().AttachWeapon(weaponA);

        //weaponA.GetComponent<AttachWeapon>().Attach(playerA, playerA.GetComponent<PlayerInfo>().rightRotator);

        //set up HUD
        Debug.Log(canvas + " HealthA  " + healthA);
        healthA = (GameObject)GameObject.Instantiate(healthBarPrefab, new Vector3(960, -768, 0), Quaternion.identity);
        Debug.Log(canvas + " HealthA  " + healthA + "    SECOND");
        healthA.transform.SetParent(canvas.transform, false);
        healthA.GetComponent <HealthBar>().SetIcon(player0Data.characterIcon);
        playerA.GetComponentInChildren <ReceiveDamageOnCollision>().healthBar = healthA.GetComponent <HealthBar>();
        playerA.GetComponentInChildren <ReceiveDamageOnCollision>().health    = 100 * player0Data.stats.health;

        playerA.GetComponentInChildren <RigidBodyTopDownMovement>().speedMultiplier = 1 + player0Data.stats.speed;


        Debug.Log("B");

        playerPrefab = characterPrefabs[player1Data.characterID];
        weaponPrefab = weaponPrefabs[player1Data.weaponID];

        Vector3 posB = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance);

        while (Vector3.Magnitude(pos - posB) < 8)
        {
            posB = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance);

            while (NavMesh.SamplePosition(posB, out _hit, 0.4f, NavMesh.AllAreas) == false)
            {
                posB = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance);
                Debug.Log("CantspawnB");
            }
        }
        playerB = (GameObject)GameObject.Instantiate(
            playerPrefab,
            posB,
            Quaternion.identity);
        cameraReference.b = playerB.GetComponentInChildren <RigidBodyTopDownMovement>().gameObject;

        playerB.GetComponent <PlayerInfo> ().controller = PlayerInfoPasser.GetController(1);
        playerB.GetComponent <PlayerInfo>().AssignPlayer(1);

        GameObject weaponB = (GameObject)GameObject.Instantiate(weaponPrefab, posB, Quaternion.identity);

        //weaponB.transform.Rotate(0, 0, 90);
        playerB.GetComponent <PlayerInfo>().AttachWeapon(weaponB);

        //weaponB.GetComponent<AttachWeapon>().Attach(playerB, playerB.GetComponent<PlayerInfo>().rightRotator);

        healthB = (GameObject)GameObject.Instantiate(healthBarPrefab, new Vector3(960, -768, 0), Quaternion.identity);
        healthB.transform.SetParent(canvas.transform, false);
        healthB.GetComponent <RectTransform>().localScale = new Vector3(-1, 1, 1);
        healthB.GetComponent <HealthBar>().SetIcon(player1Data.characterIcon);
        playerB.GetComponentInChildren <ReceiveDamageOnCollision>().healthBar = healthB.GetComponent <HealthBar>();
        playerB.GetComponentInChildren <ReceiveDamageOnCollision>().health    = 100 * player1Data.stats.health;

        playerB.GetComponentInChildren <RigidBodyTopDownMovement>().speedMultiplier = 1 + player1Data.stats.speed;

        Debug.Log("Done");
    }