Adding coins to level 2 & 3

OK, so confusing, because I looks like a normal e-mail and like I am getting the reply from you and that I can reply to you from there.

I uploaded the zip to my repo.
Once again I am grateful for your patience and help.
About the tutorial… On my screen github is black and instead of saying create it says new. Even GitHub Desktop looked different. Small variations like that. Even in Unity. I had to look for a long time for a setting that wasn’t in the same place as his was for me.
Once again, thank you thank you thank you!

All The Best, Serafín Ziquer Xavier and have a great weekend!

Thanks. I downloaded the zip, and I was able to open the project. Solving the problem with the non-collectable coins took me a while but the fix was very simple: The player did not have the “Player” tag assigned in Level 2 and 3. I was looking at the assigned “Layer” and thought that was the tag until I logged the tag into the console. The console said “untagged” but the code needs:

if (other.tag == "Player" && !wasCollected)

Then I took a closer look at the Inspector and noticed my mistake.
image


However, I still cannot hear the sound when I collect a coin in level 2, even though the “One shot audio” game object appeared in the Hierarchy. When I disable the CinemachineBrain component on the Player, I am able to hear the sound. I did some research and found a thread by another student. For them, the fix was to set the “Update Method” of the CinemachineBrain to “Manual Update”.

image

Unfortunately, the camera will not move anymore with that setting.

I fixed that problem by moving the AudioListener to a non-moving game object: “Cameras”. I also added a new class: AudioListenerPosition.

image

The AudioListenerPosition simply returns the position of this component/game object. This is a more performant solution than calling FindObjectOfType whenever you want to play a sound clip.

using UnityEngine;

[RequireComponent(typeof(AudioListener))]
public class AudioListenerPosition : MonoBehaviour
{
    static AudioListenerPosition instance = null;
   
    void Start()
    {
        instance = this;
    }

    public static Vector3 GetPosition()
    {
        if (instance == null) { return Vector3.zero; }
        return instance.transform.position;
    }
}

And in the CoinPickup class:

Vector3 position = AudioListenerPosition.GetPosition();
AudioSource.PlayClipAtPoint(coinPickupSFX, position);

Did this fix it for you?


See also:

OMG Nina! I have looked and looked, I swear that I checked it, but I guess I was blind in the end. The only thing I needed to do was to tag the player. I remember you even suggested that before and I remember that I checked it again after you asked me. My God! Sorry! And 1000 thanks for all your help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms