Find Position of Destroying Object ?

Hello, I want to take a text to a position of the collectible that player just take.

The collectible object is destroying after player is collecting them, so how can I achieve this effect?

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

public class Collectibles : MonoBehaviour {

	public static int scoreValue;

	public bool alreadyScored;

	public float spawnX, spawnY;

	void Start()
		spawnX = transform.position.x;
		spawnY = transform.position.y;

	void OnTriggerEnter2D (Collider2D col) {
		if (col.gameObject.layer == LayerMask.NameToLayer ("Player")) {

			if (alreadyScored)
			alreadyScored = true;

			ScoreManager.score += scoreValue;
			ScoreManager.collected = true;

		} else {
			ScoreManager.collected = false;

Pass to ScoreManager the position of the Collectible that is being picked up, and instantiate a game object (probably a prefab) with Text component on it at that position (this function will help you position the Text correctly). Then you can Destroy() your Collectible.

2 questions though:

  • what is the purpose of scoreValue being static? Put in a different way, why do all the Collectibles need to share this variable?

  • what is the purpose of ScoreManager.collected? Doesn’t alreadyScored provide the same functionality, but better?