我正在尝试创建一个平台,该平台可以使玩家自己移动。无论是水平还是垂直。我试图通过将玩家的父母设置为平台来做到这一点,但是玩家并不坚持。这是我要使用的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Platform : MonoBehaviour
{
public GameObject player;
public GameObject platformAnchor;
public float movementSpeed;
void Update()
{
transform.position = Vector3.Lerp(transform.position, platformAnchor.transform.position, (Time.deltaTime * movementSpeed));
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject == player)
{
other.transform.parent = transform;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject == player)
{
other.transform.parent = null;
}
}
}