public void CmdSpawnPotions(ElementStruct p) { ElementEnum.Elements type = (ElementEnum.Elements)p.elementType; GameObject temp = null; switch (type) { case ElementEnum.Elements.Ash: potionAsh.transform.position = p.position; potionAsh.GetComponent <Element>().elementType = type; temp = Instantiate(potionAsh); temp.gameObject.name = "Ash"; temp.transform.parent = null; break; case ElementEnum.Elements.Fire: potionFire.transform.position = p.position; potionFire.GetComponent <Element>().elementType = type; temp = Instantiate(potionFire); temp.gameObject.name = "Fire"; temp.transform.parent = null; break; case ElementEnum.Elements.Grass: potionGrass.transform.position = p.position; potionGrass.GetComponent <Element>().elementType = type; temp = Instantiate(potionGrass); temp.gameObject.name = "Grass"; temp.transform.parent = null; break; case ElementEnum.Elements.Water: potionWater.transform.position = p.position; potionWater.GetComponent <Element>().elementType = type; temp = Instantiate(potionWater); temp.gameObject.name = "Water"; break; case ElementEnum.Elements.Cheese: potionCheese.transform.position = p.position; potionCheese.GetComponent <Element>().elementType = type; temp = Instantiate(potionCheese); temp.gameObject.name = "Cheese"; temp.transform.parent = null; break; } if (temp != null) { NetworkServer.Spawn(temp); } }
public static ElementStruct LoadElementFromFile(string id) { ElementStruct elementStruct = new ElementStruct(); string[] allLines = System.IO.File.ReadAllLines("../../objects.txt"); foreach (string line in allLines) { string[] splitLine = line.Split(); if (splitLine[0] == id) { elementStruct.description = RemoveSpaces(splitLine[1]); elementStruct.sprite = splitLine[2][0]; elementStruct.id = id; } } return(elementStruct); }
public List <ElementStruct> SpawnPotions() { previousSpawnPoints = new List <Vector3>(); spawnedPotions = new List <ElementStruct>(); for (int i = 0; i < elementsToSpawn; i++) { bool foundPosition = false; Vector3 spawnPoint = new Vector3(0, 0, 0); while (!foundPosition) { BoxCollider spawn = gameObject.GetComponent <BoxCollider>(); //get the spawn point spawnPoint = new Vector3(UnityEngine.Random.Range(spawn.bounds.min.x, spawn.bounds.max.x), spawn.transform.position.y, UnityEngine.Random.Range(spawn.bounds.min.z, spawn.bounds.max.z)); //check for overlap Collider[] colliders = Physics.OverlapSphere(spawnPoint, 1); // If this collider is tagged "Obstacle" if (colliders.Length <= 2) { // Then this position is not a valid spawn position validPosition = true; } else { validPosition = false; } //Make sure potions are spaced out foreach (Vector3 sp in previousSpawnPoints) { if (Vector3.Distance(spawnPoint, sp) < 5) { validPosition = false; } } //if it has not previously spawned at this position and is not overlapping //then spawn a potion if (!previousSpawnPoints.Contains(spawnPoint) && validPosition) { foundPosition = true; } } //Debug.Log("Spawn"); //reset valid boolean validPosition = false; ElementStruct temp = new ElementStruct(); //set the material and element type of the potion temp.elementType = ChangeMaterial(); //instatiate the gameobject and assign it to a variable so that it can be added as a child //GameObject p = Instantiate(potion, spawnPoint, transform.rotation); //add the potion as a child to the spawn area object //p.transform.parent = transform; temp.position = spawnPoint; spawnedPotions.Add(temp); //add the transform to the list of previously used locations previousSpawnPoints.Add(spawnPoint); } return(spawnedPotions); }
public void RpcSpawnPotions(ElementStruct p) { CmdSpawnPotions(p); }