protected override void Shoot() { float currentShotAngle = FirstAngleShot; for (int i = 0; i < NbrBulletPerShot; i++) { bullet = ObjectsPooler.GetSingleton.GetPooledObject(tagBullet, false); //cree un bullet if (!bullet) { Debug.LogError("y'en a + que prévue, voir dans objectPool pour ajouter des bullet"); return; } bullet.transform.SetParent(GameManager.GetSingleton.ObjectDynamiclyCreated); //set le parent bullet.transform.rotation = transform.rotation; //set la position //Vector3 projectileOrientation = new Vector3(Mathf.Cos(Mathf.Deg2Rad * currentShotAngle), Mathf.Sin(Mathf.Deg2Rad * currentShotAngle), 0); Quaternion rotationForTheShoot = Quaternion.Euler(new Vector3(0, 0, currentShotAngle)); Vector3 projectileOrientation = rotationForTheShoot * transform.right; bullet.transform.position = transform.position + projectileOrientation * forwardBullet; //set la rotation //get le projectile du bullet, et le setup (qui peut être de plusieurs types !) Projectile projectile = bullet.GetComponent <Projectile>(); float initSpeed = 0.0f; if (PlayerController) { initSpeed = (isMovingRight) ? PlayerController.PlayerBody.velocity.magnitude * AdditionalSpeed : 0f; } projectile.Setup(PlayerController, initSpeed, projectileOrientation); if (PlayerController) { GiveDamage giveDamage = bullet.GetComponent <GiveDamage>(); giveDamage.LinkToPlayer(PlayerController); projectile.ColorBullet = PlayerController.ColorPlayer; } //enfin, l'activer bullet.SetActive(true); currentShotAngle += angleBetweenEachShoot; } }
void OnCollisionEnter(Collision collision) { GiveDamage bullet = collision.gameObject.GetComponent <GiveDamage>(); if (bullet == null) { return; } bool isPlayer = GetComponent <PlayerInput>(); HEALTH_POINT -= bullet.GetDamage(); Debug.Log(gameObject.name + " " + HEALTH_POINT); if (HEALTH_POINT <= 0) { if (_audio != null) { _audio.clip = deathSound; _audio.Play(); } Debug.Log("isPlayer: " + isPlayer); if (isPlayer) { GetComponent <Animator>().SetBool("death", true); UIManager.Instance.loose(); } else // is monster { if (OnDead != null) { Debug.Log("OnDead"); OnDead.Invoke(); kill(); } } } }