Hello guys, i’ve got two kind of problem here: Scenario: my game is a 3D game where the player is a tank, written in c#, divided in two different phases (first phase, the camera is attached to the turret with the audio listener inside it and you can shoot but never move;
second phase where you move inside 3 different lanes to avoid obstacles, but you can’t shoot).
My problems:
1- I’m using raycast to shoot the enemies in the first phase (please don’t say to change this method, because my boss wants that I use this and I must use it). Enemies have got a collider (player tank too), but there is a problem with the maxDistance parameter that takes Physic.raycast. The problem is that the bullet reaches the enemy, but it not disappears when it hits the collider, it always go a little more forward, and then it recognizes that it hits a collider. It happens when the player fires and hits the enemy and when the enemy fires and hits the player. I think the problem is inside “playerRayEndPos” and “enemyRayEndPos” that you can check inside my code, but I don’t know how to fix it.
My code for that: void Update () { if (enableBullet) { bulletPos = gameObject.transform.p - Pastebin.com
2- I’ve got two bugs with the audio ingame:
2.1) i want that in a precise moment (that’s why I need to do this inside the update function), my game pauses and play an audio clip. When the audioclip is finished playing, the game resumes. I don’t know why this don’t work and I can’t seem to find a solution.
My code for this: //Inside void Update()if (!keepChangePhase) { if (!phaseChanged) { - Pastebin.com
2.2) (always inside update() ) I want that when the player aims to an enemy, a “beep” audioclip plays. I was able to do this and it works, but when I press arrow keys to move the turret of the tank and the beep is still playing, the pitch of that audioclip automatically changes the pitch (if i move to the left the pitch is higher, to the right is lower). I tried to force the pitch to be 1f, but it doesn’t work. Why this?
My code for that: Vector3 fwd = playerBulletSpawnPoint.transform.TransformDirection (Vector3.forwa - Pastebin.com
Thank you in advance guys!