Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Character collecting item issue

Discussion in 'Scripting' started by thebossgamer350, Jul 18, 2023.

  1. thebossgamer350

    thebossgamer350

    Joined:
    Jul 18, 2023
    Posts:
    1
    I m stuck in this issue, so i m trying to make my player collect a item, i do have the tag in the object and box colliders and everything , but when my player hits nothing happens , i tried to add a debug log but it doesnt let me i get this message in unity : Assets\Game\Scripts\Player\ItemCollector.cs(10,9): error CS0104: 'Debug' is an ambiguous reference between 'UnityEngine.Debug' and 'System.Diagnostics.Debug'



    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using UnityEngine;

    public class ItemCollector : MonoBehaviour
    {
    private void OnTriggerEnter2D(Collider2D collision)
    {
    Debug.Log("The GameObject with the tag 'dk' has been collided with.");
    GameObject gameObject = collision.gameObject as GameObject;
    if (gameObject.tag == "dk")
    {
    Destroy(gameObject);
    }
    }
    }
     
  2. Chubzdoomer

    Chubzdoomer

    Joined:
    Sep 27, 2014
    Posts:
    105
    The error message is letting you know that the UnityEngine and System.Diagnostics namespaces both contain a Debug class, and so the script can't possibly know which one you want to use unless you specify it (by typing either UnityEngine.Debug or System.Diagnostics.Debug).

    In your case, just change the Debug line to:
    UnityEngine.Debug.Log("The GameObject with the tag 'dk' has been collided with.");


    Alternatively, you can just get rid of the System.Diagnostics line at the top unless there's a specific reason you need it.

    Also, please use code tags when posting code in the future!
     
  3. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    maybe u dont have 2d rigidbody or 2d colliders

    also

    remove using System.Diagnostics; from your code