- Home /
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
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
Answer by MickyX · Jun 05 at 09:08 PM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613061426im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Passing two GameObjects to a C# onClick script 1 Answer
How do i determin if an objects rotation is between 2 values on each axis? 0 Answers
Cloning Objects with Instantiate() - variables/references for added Components not stored? 3 Answers