How do I Convert/Replace an object with another object and make the replaced object behave exactly the same as the replaced object?

Hello guys,

I am trying to make a game Hyper Casual game like the Atm Rush game and I am having trouble making the money portal thing that convert the dollar to gold and from gold to diamond. I tried using a lot of different methods to accomplish this but nothing seems to work. I don’t know where is the problem. I have been trying to make this for almost 5 hours now and I am still stuck.

This is what I wrote:

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

public class MoneyConverter : MonoBehaviour
{
    
    public MoneyState currentMoneyState;
    public GameObject dollar;
    public GameObject gold;
    public GameObject diamond;

    public enum MoneyState { dollar, gold, diamond }

    public void ChangeState(MoneyState newState)
    {

        if (newState == MoneyState.gold)
        {
            dollar.SetActive(false);
            gold.SetActive(true);
  
        }
        else if (newState == MoneyState.diamond)
        {
            gold.SetActive(false);
            diamond.SetActive(true);

        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {

            if (currentMoneyState == MoneyState.dollar )
            {
                ChangeState(MoneyState.gold);
                currentMoneyState = MoneyState.gold;
            }

            else if (currentMoneyState == MoneyState.gold)
            {
                ChangeState(MoneyState.diamond);
                currentMoneyState = MoneyState.diamond;


            }


        }
    }

}

This is the script that I have used for the money converter portal. The thing is my compiler does not display any error that’s also why I am having trouble with this.

The main problem is that when I pickup more than one object the portal only converts the first object that I have picked up don’t know why. Another problem is that the OnTriggerEnter is being executed more than one time what I mean is that when the MoneyState is on dollar it instantly converts it to gold then diamond which is wrong each portal should convert the money only once not a multiple time.

Can someone please help me? Or at least just give me an advise on how should I approach this problem? Also Can someone tell me how does the principle work for this money converter portal? Should the script that converts the money be attached to the portal itself or the money object?

This Converter portal does it have an actual name so that I can look it up on the internet? Just to see if there is something similar to what I am doing?

Any help would be appreciated.

Thank you.

Whenever you pick up an object add it to an array or a list of gameobjects… Then instead of using SetActive try using Instantiate in something like a for or foreach loop to cover all the GameObjects… If you would like a code example I can provide one :slight_smile: