将吃豆人传送到迷宫的另一边

Teleporting PacMan to other side of the Maze

我正在为我的 PacMan 游戏创建传送,以便在触发时到达迷宫的另一边。那时我有代码,但是碰撞时什么也没有发生。我需要在触发左门户时转到右门户。我在想我的 Pathfinding 可能是问题所在。谢谢

传送门密码

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

public class Portal : MonoBehaviour
{
    public Transform warpTarget;

    void onTriggerEnter2D(Collider2D other){
        Debug.Log("An Object Collided");
        other.gameObject.transform.position = warpTarget.position;
    }
}

也许您应该检查方法的名称。它必须以 大写字母 字符开头,而不是小写字母,所以它应该是这样的:

private void OnTriggerEnter2D(Collider2D other)
{
     Debug.Log("An Object Collided");
     other.gameObject.transform.position = warpTarget.position;
}