void Atirar() { if (entroNoRange == true) { for (int i = 0; i <= 3; i++) { GameObject projetil = ProjetilPool.GetInstance().Create(_projetilRefTranform.position, _projetilRefTranform.rotation, 2); projetil.GetComponent <Rigidbody2D>().velocity = (_playerTransform.position - _inimigoTranform.position) * 1f; //joga o objeto } entroNoRange = false; } }
public void Atira(Vector3 direcao) { GameObject projetil = ProjetilPool.GetInstance().Create(_projetilRef.position, _projetilRef.rotation, 1); projetil.GetComponent <Rigidbody2D>().velocity = direcaoNormalized(direcao) * _projetilVelocidade; //joga o objeto /*/https://philipperocha.wordpress.com/2016/05/29/criando-emissao-de-projeteis-para-o-personagem-como-forma-de-ataque-aos-inimigos/ * //http://equilibrecursos.com.br/2013/12/unity-3d-17-atirando-projeteis-parte-2-tiros-estilo-megaman/ * GameObject projetil = GameObject.Instantiate(_projetilPrefabObjet, _projetilRef.position, _projetilRef.rotation); //Estancia objeto * projetil.GetComponent<Rigidbody2D>().velocity = direcaoNormalized(direcao) * _projetilVelocidade; //joga o objeto * //ObjectPool.GetInstance().Create(spawnBullet.position, Quaternion.identity, direction);*/ }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("inimigo") && origin == 1) { other.gameObject.GetComponent <InimigoCtr>().inimigo.TomarDano(dano); ProjetilPool.GetInstance().ReturnToPool(this.gameObject); } else if (other.gameObject.CompareTag("Player") && origin == 2) { other.gameObject.GetComponent <PlayerCtr>().player.TomarDano(dano); ProjetilPool.GetInstance().ReturnToPool(this.gameObject); } else if (other.gameObject.CompareTag("parede")) { ProjetilPool.GetInstance().ReturnToPool(this.gameObject); } }
private void Awake() { if (uniqueInstance == null) { uniqueInstance = this; } else { Destroy(this.gameObject); } pooling = new GameObject[maxObjects]; for (int i = 0; i < maxObjects; i++) { pooling[i] = GameObject.Instantiate <GameObject>(prefab); pooling[i].SetActive(false); DontDestroyOnLoad(pooling[i]); } }