How can I set parameter of player clone ?

Hi. I made a transfer code, if player clone touched the door, player will transfer to another room. But it doesn’t work. I think ‘currentMapName’ is only set in player object, not clone object. So I want to know how can I set parameter of clone object. Thanks for anything your helps.


the error code

197191-20220605-232429.png


transfom source code

    public string  transferMapName; // map name for transform

    private PlayerScript thePlayer;

    // Start is called before the first frame update
    void Start()
    {
        thePlayer = FindObjectOfType<PlayerScript>(); // player objects.
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.name == "Player(Clone)")
        {
            Debug.Log("Hit door");
            thePlayer.currentMapName = transferMapName;
            Debug.Log(thePlayer.currentMapName);
            SceneManager.LoadScene(transferMapName);
        }
    }

and clone parameter that I want set value
197192-20220605-232958.png

@foruniv00

Does your Player(Clone) have the player script on also?

Do you instantiate the Player(Clone)? If so you can transfer Players “CurrentMap Name” to the cloned players PlayerScript at the point of instantiation.

Alternatively, it looks like the script hasn’t found the “thePlayer”, try using

        thePlayer = GameObject.Find("Player").GetComponent<PlayerScript>();

In place of FindObjectOfType