![](/img/trans.png)
[英]Player not moving down with gravity after transforming position - UNITY 2D
[英]player not moving to requested position - unity 2D
我的目标是在门的半径范围内,当你按下你移动场景并移动到门的 position 但无论我尝试什么,我的播放器都不会移动到那里。 有任何想法吗?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Door : MonoBehaviour
{
public string sceneToWarpTo;
public string doorScene;
public float doorLocationX;
public float doorLocationY;
public GameObject player;
private float x;
private float y;
// Start is called before the first frame update
void Start()
{
x = player.transform.position.x;
y = player.transform.position.y;
}
// Update is called once per frame
void Update()
{
}
IEnumerator LoadFixThing()
{
//yield on a new YieldInstruction that waits for 5 seconds.
yield return new WaitForSeconds(1);
}
public void OnTriggerStay2D(Collider2D coll) {
if (coll.tag == "Player"){
if(Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)){
Debug.Log("Enter Door");
Debug.Log("warping to " + sceneToWarpTo + " from " + doorScene);
SceneManager.LoadScene(sceneToWarpTo);
LoadFixThing();
player.transform.position = new Vector2(doorLocationX, doorLocationY);
Debug.Log("player pos: " + player.transform.position);
Debug.Log("door pos: " + this.transform.position);
Debug.Log(player.name);
}
}
}
}
我真的不知道还能说什么,但它一直在说我的问题需要更多信息,所以感谢您阅读我的问题:)
嗯...你不应该在移动播放器后调用 SceneManager.Loadscene 吗? 先试试那个..
如果是开新场景,则当前玩家object连同上一个场景一起被销毁。 如果你想持久化它,你可以使用DontDestroyOnLoad
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.