float getHeightDistanceFromPlatform(Plataforma p, Vector3 point) { float result = -8000; if (p != null) { Vector3 highestPoint = plataforma.GetComponent <BoxCollider>().bounds.center; highestPoint.y += plataforma.GetComponent <BoxCollider>().bounds.size.y / 2; result = Mathf.Abs(highestPoint.y - (charController.bounds.center.y - charController.bounds.size.y / 2)); } return(result); }
public void spawnarGeometria <Y>(int distanciaObjetoPlataforma, Vector2 inipos) { if (!typeof(Y).IsSubclassOf(typeof(Geometria))) { return; } inipos = plataforma_ref.transform.position; Vector3 position = inipos; //bounds.size.x/2 certo? float sizeT = plataforma_ref.GetComponent <SpriteRenderer>().bounds.size.x / 2; //pq trabalhar aqui com o spriteRenderer da plataforma? position.x = Random.Range(position.x - sizeT, position.x + sizeT); position.y = distanciaObjetoPlataforma; position.z = -1f; if (listaGeometria.Count > 0) { if (typeof(Y) == typeof(Bola)) { if (listaGeometria.OfType <Bola>().Any()) //pegar todos os elementos do tipo bola não é uma condição? { int index = listaGeometria.FindLastIndex(x => x.GetType() == typeof(Bola)); //aqui salva a posição na lista? Bola b = (Bola)listaGeometria[index]; listaGeometria.RemoveAt(index); b.transform.position = position; b.gameObject.SetActive(true); } } } }
public bool MoveToPoint(Plataforma dest) { if (!walking & alive & !atacking) { if (currentPlatform.GetComponent <Plataforma>().isReachable(dest)) { currentPlatform.entity = null; currentPlatform = dest; if (dest.entity == null) { dest.entity = this.gameObject; } dest.moved(); Debug.Log("destination setted"); agent.SetDestination(dest.transform.position + offset); return(true); } } Debug.Log("return false"); return(false); }
public void spawnarGeometria <T>(int distanciaBolaPlataforma, Vector2 inicialPos) { if (!typeof(T).IsSubclassOf(typeof(Geometria)))//aqui verifica se o T é filho da geometria { return; } inicialPos = plataforma_ref.transform.position; Vector3 position = inicialPos; float sizeX = plataforma_ref.GetComponent <SpriteRenderer>().bounds.size.x / 2; position.x = Random.Range(position.x - sizeX, position.x + sizeX); position.y = distanciaBolaPlataforma; position.z = -1; if (poolGeometrias.Count > 0) //quando tiver q spawnar se tem objetos na pool, utilizar eles senão criar um novo { //não entrara neste if se não houver nada na pool if (typeof(T) == typeof(Bola)) { if (poolGeometrias.OfType <Bola>().Any()) //aqui o ofType é para pegar todos os elementos do tipo bola { int index = poolGeometrias.FindLastIndex(x => x.GetType() == typeof(Bola)); // salva a posição Bola b = (Bola)poolGeometrias[index]; poolGeometrias.RemoveAt(index); // retira da lista b.transform.position = position; //aqui acha a localização da bola b.gameObject.SetActive(true); } } else if (typeof(T) == typeof(Quadrado)) { if (poolGeometrias.OfType <Quadrado>().Any()) { int index = poolGeometrias.FindLastIndex(x => x.GetType() == typeof(Quadrado)); Quadrado b = (Quadrado)poolGeometrias[index]; poolGeometrias.RemoveAt(index); b.transform.position = position; b.gameObject.SetActive(true); } } else if (typeof(T) == typeof(Triangulo)) { if (poolGeometrias.OfType <Triangulo>().Any()) //aqui o ofType é para pegar todos os elementos do tipo bola { int index = poolGeometrias.FindLastIndex(x => x.GetType() == typeof(Triangulo)); // salva a posição Triangulo b = (Triangulo)poolGeometrias[index]; poolGeometrias.RemoveAt(index); // retira da lista b.transform.position = position; //aqui o position é onde o objeto sera spawnada b.gameObject.SetActive(true); } } } else { if (typeof(T) == typeof(Bola)) { Instantiate(bolaPrefab, position, Quaternion.identity); } else if (typeof(T) == typeof(Quadrado)) { Instantiate(quadradoPrefab, position, Quaternion.identity); } else if (typeof(T) == typeof(Triangulo)) { Instantiate(TrianguloPrefab, position, Quaternion.identity); } } }