Adding coins to level 2 & 3

I ran in to a little problem and that is. When I ad the coins to level 2 an 3, then the player can’t pick them up. It works on level 1. Any ideas?
Cheers!

Hi,

Are there any error messages in your console in level 2 and 3? Have you already tried to add Debug.Logs to your code to see what is going on during runtime?

Yes, now I have. Every time I jump on the coin, the console says: hi
UnityEngine.Debug:Log (object)
CoinPickup:OnTriggerEnter2D (UnityEngine.Collider2D) (at Assets/Scripts/CoinPickup.cs:13) "

But the coin ain’t getting picked up.
Cheers!

my code btw…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CoinPickup : MonoBehaviour
{

[SerializeField] AudioClip coinPickupSFX;


void OnTriggerEnter2D(Collider2D other) 
{
    Debug.Log("hi");
    if (other.tag == "Player")
    {

        AudioSource.PlayClipAtPoint(coinPickupSFX, Camera.main.transform.position);
        Destroy(gameObject);
    }
}

}

What about the if-block. Does it get executed? If so, how did you check that?

To be honest and I have been trying to figure it out. But I don’t know where to write the if-block.
:neutral_face:

You already have an if-block in your OnTriggerEnter2D method. Add another Debug.Log to that if-block to see if it gets executed.

Since “hi” got logged into your console, you know that OnTriggerEnter2D got called. However, just because OnTriggerEnter2D got called does not mean that the if-block got executed, too.

Thanks for your patience with me Nina.
It says:

UnityEngine.Debug:Log (object)
CoinPickup:OnTriggerEnter2D (UnityEngine.Collider2D) (at Assets/Scripts/CoinPickup.cs:13)

Great. I assume you tested the code in level 1 and level 2? If so, you can assume that the problem is not caused by your code.

Select the Main Camera game object in level 2. Does it have the “Main Camera” tag assigned in its Inspector? Is there an Audio Listener component attached to the Inspector?

You do not have any other cameras in your scene, do you? Since the PlayClipAtPoint method spawns a new AudioSource at Camera.main.transform.position, it might be that the sound does get played but you cannot hear it because it is too far away from the camera rendering your scene.

If your audio clip worked in level 1, check if there are any differences in level 2.

I have mai camera and state driven camera. Under state driven camera, I have Run, idle and ladder camera on all the levels.I have been starring at all the settings for two days now, without finding any differences. But I have also experienced that sometimes,es you look so hard, that you go blind from seeing what is wrong with the codes and settings sometimes.
The settings are all the same from level one, two and 3.


Why do you have an AudioSource attached to “Coin (1)”? Is “Coin (1)” a game object in level 1 (= the working level) or level 2 (= the broken level)?

What happens if you prefab the coin from the working level and drag the prefab into the broken levels? Does the new coin work?

Every time I drag the coin in to the scene of the level, it comes coin 1, 2 and 3. In the first level I have 3 coins and they all work. I drag from the prefabs. When I do the same in level 2 and 3, it doesn’t work.
Coin 1 is a gameobject in level 1.

Could you please upload your project to GitHub without the Temp and Library folder and share a link to the public repository here? I’d like to take a look into this.

Here is a tutorial video by Brackeys:

https://www.youtube.com/watch?v=qpXxcvS-g3g

Hi Nina, sorry in advance if I have done something wrong Now I feel small. I had to watch another tutorial video to understand it better. Here goes nothing:

Unfortunately, that’s not the complete project. The entire Assets folder with your scripts and scene(s) is missing. What was the problem with Brackey’s tutorial?

If creating a repo is too difficult, zip your project, upload it somewhere on the internet and share a link here. Do not upload the Library and/or Temp folders. My internet connection is fairly slow.

Okay, sorry. Let me see what I can do. I am not sure there is something wrong with Brackey’s tutorial. But he is on a Windows computer and I am on a Mac. So everything looks different. Even when I log on GitHub. I have bought a PC laptop, where I will do all the tutorials in the future. I just need to finish this session.

What exactly looks different? Actually, git/Github are platform independent. This is the first time I read that somebody was not able to create a repository with Brackeys tutorial. :confused:

You actually managed to create a repository. I was able to download your project. The only problem is that files/folders are missing.

If a git repo does not work for you, zip your project folder (without the Library and Temp folders). That’s a bit less convenient for me but we could make an exception. :slight_smile:

1 Like

Hi Nina, I have replied on the email I got from this reply with a zip file. Maybe that was wrong?
All The Best, Serafín

When I messed up game objects dealing with prefabs in earlier tutorial segments, it ended up being that I was setting up the game object instead of the prefab and forgot to apply the override changes from that object to the prefab. If this is something else I’d like to know what went wrong for you, but this sounds like the same issue I had setting up my enemies where one works and the rest don’t.

1 Like

What e-mail? If you created a repo or made a commit, it might be that GitHub sends you an e-mail. You won’t get an e-mail by me (or another Gamedev.tv teaching assistant).

I will check it out. Right now I think I have already try this. But I will look at it again.