Beispiel #1
0
    public void AddBot(bool useRandomColor)
    {
        string name = nameGenerator.GetRandomName();

        if (!ballDictionary.ContainsKey(name))
        {
            //Create ball
            GameObject ball = Instantiate(botPrefab);

            ball.transform.parent = parent;
            ball.name             = name;
            ball.transform.GetChild(0).GetComponent <Ball>().gameController = gameObject;
            //not for bots
            //ball.transform.GetChild(0).GetComponent<BallCollision>().ballConfig = ballConfig;
            ball.transform.GetChild(0).GetComponent <BallCollision>().InitializeConfig();

            //Add to dictionary
            if (unusedSpawnpoints.Count == 0)
            {
                GenerateSpawnPoints();
                Debug.Log("Ran out of spawnpoints, reused them");
            }

            ball.transform.position = GetSpawnPoint();
            ballDictionary.Add(name, ball);
            GetComponent <PlayerCount>().AddPlayer();
            if (GetComponent <PlayerCount>() == null)
            {
                Debug.LogError("ERROR! PlayerCount's text is not set in GameController. Did you apply it in this scene?");
            }

            if (useRandomColor)
            {
                MeshRenderer meshRenderer = ball.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <MeshRenderer>();
                Debug.Log(ball.transform.GetChild(0).GetChild(0).GetChild(0).GetChild(0).name);
                BallMaterial rand = (BallMaterial)(ballDictionary.Count % materialDictionary.Count) + 1;
                if (materialDictionary.ContainsKey("BallMaterial" + rand.ToString()))
                {
                    meshRenderer.material = materialDictionary["BallMaterial" + rand.ToString()];
                }
                else
                {
                    Debug.LogError("Error! Attempted to load a random material (" + rand + ")which could not be found!");
                }
            }
        }
        else
        {
            Debug.LogWarning("Error! Attempted to create ball using a name that already exists");
        }
    }
Beispiel #2
0
    public GameObject AddBall(string name, BallMaterial ballMaterial)
    {
        Debug.Log(ballMaterial);
        if (!ballDictionary.ContainsKey(name))
        {
            //Create ball
            GameObject ball = Instantiate(ballPrefab);

            ball.transform.parent = parent;
            ball.name             = name;

            ball.transform.GetChild(0).gameObject.GetComponent <Ball>().gameController      = gameObject;
            ball.transform.GetChild(0).gameObject.GetComponent <BallCollision>().ballConfig = ballConfig;
            ball.transform.GetChild(0).gameObject.GetComponent <BallCollision>().InitializeConfig();

            //Add to dictionary
            if (unusedSpawnpoints.Count == 0)
            {
                GenerateSpawnPoints();
                Debug.Log("Ran out of spawnpoints, reused them");
            }

            ball.transform.position = GetSpawnPoint();
            ballDictionary.Add(name, ball);
            GetComponent <PlayerCount>().AddPlayer();
            if (GetComponent <PlayerCount>() == null)
            {
                Debug.LogError("ERROR! PlayerCount's text is not set in GameController. Did you apply it in this scene?");
            }

            MeshRenderer meshRenderer = ball.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <MeshRenderer>();

            //Set material
            switch (ballMaterial)
            {
            case BallMaterial.RANDOM:
                BallMaterial rand = (BallMaterial)(ballDictionary.Count % materialDictionary.Count) + 1;
                if (materialDictionary.ContainsKey("BallMaterial" + rand.ToString()))
                {
                    meshRenderer.material = materialDictionary["BallMaterial" + rand.ToString()];
                    Debug.Log(meshRenderer.material);
                }
                else
                {
                    Debug.LogError("Error! Attempted to load a random material (" + rand + ")which could not be found!");
                }
                break;

            default:
                if (materialDictionary.ContainsKey("BallMaterial" + ballMaterial.ToString()))
                {
                    meshRenderer.material = materialDictionary["BallMaterial" + ballMaterial.ToString()];
                }
                else
                {
                    Debug.LogError("Error! Attempted to load the material " + ballMaterial.ToString() + " which could not be found!");
                }
                break;
            }

            if (name == "Ragntard")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialRagntard", ball);
            }
            else if (name == "Mickster_man")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialMickster_man", ball);
            }
            else if (name == "Jellyfranky")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialJellyFranky", ball);
            }
            else if (name == "Lofi_lime")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialLofi_Lime", ball);
            }
            else if (name == "Ksmoonblast")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialKsmoonblast", ball);
            }
            else if (name == "Scoutovich")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialScoutovich", ball);
            }
            else if (name == "Streamspinners")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialStreamSpinners", ball);
            }
            else if (name == "Felix_time")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialFelix_Time", ball);
            }
            else if (name == "Droopygoop")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialDroopygoop", ball);
            }
            else if (name == "Swarmsurvivor")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialSwarmsurvivor", ball);
            }
            else if (name == "Mariliez")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialMariliez", ball);
            }
            else if (name == "Torthom")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialTorthom", ball);
            }
            else if (name == "Obagovo")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialObagovo", ball);
            }
            return(ball);
        }
        else
        {
            Debug.LogWarning("Error! Attempted to create ball using a name that already exists");
            return(null);
        }
    }