Hi All,
Having trouble with getting the below code to play ball. To sum it up, when interacting with a door the player should be sent to another scene and then transformed (as if they have come through the door ect). The scene changes fine, everything functions correctly except that the player game object doesn’t move to the scene. Have been looking at similar posts but haven’t had any luck. Any help would be appreciated.
Have cut out the unrelated code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerInteract : MonoBehaviour
{
public GameObject currentInterobj = null;
public Interactable currentInterObjScript = null;
public Inventory inventory;
public GameObject Player;
void Update()
{
Player = GameObject.Find("Player");
if (Input.GetButtonDown("Interact") && currentInterobj)
{if (currentInterObjScript.sceneLink)
{
DontDestroyOnLoad(Player);
Scene sceneToLoad = SceneManager.GetSceneByBuildIndex(currentInterObjScript.sceneNumber);
SceneManager.LoadScene(currentInterObjScript.sceneNumber);
SceneManager.MoveGameObjectToScene(Player, SceneManager.GetSceneByBuildIndex(currentInterObjScript.sceneNumber));
Player.transform.position = new Vector3(1, -4, 1);
Debug.Log("Player moved scene");
}
}