大家好,我给游戏里加了一个移动平台,平台本身运行良好,但当我试图让玩家能站在上面时,虽然确实能站住,但在平台上移动却很不正常。移动速度非常慢,体验很差。有什么解决办法吗?我对这个系统不太了解。先谢谢大家了。
以下是平台的代码:
using System.Drawing;
using UnityEngine;
public class MovingPlatform : MonoBehaviour
{
public float platformSpeed;
public int platformStartingPoint;
public Transform[] points;
private int i;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
transform.position = points[platformStartingPoint].position;
}
// Update is called once per frame
void Update()
{
if (Vector2.Distance(transform.position, points[i].position) < 0.02f)
{
i++; // increase the index
if (i == points.Length) // checks if the platform was on the last point after the index increase
{
i = 0;
}
}
// moving the platform towards the platform to the point position with the index "i"
transform.position = Vector2.MoveTowards(transform.position, points[i].position, platformSpeed * Time.deltaTime);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (transform.position.y < collision.transform.position.y - 1.3f)
{
collision.transform.SetParent(transform);
}
}
void OnCollisionExit2D(Collision2D collision)
{
collision.transform.SetParent(null);
}
}using System.Drawing;
using UnityEngine;
public class MovingPlatform : MonoBehaviour
{
public float platformSpeed;
public int platformStartingPoint;
public Transform[] points;
private int i;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
transform.position = points[platformStartingPoint].position;
}
// Update is called once per frame
void Update()
{
if (Vector2.Distance(transform.position, points[i].position) < 0.02f)
{
i++; // increase the index
if (i == points.Length) // checks if the platform was on the last point after the index increase
{
i = 0;
}
}
// moving the platform towards the platform to the point position with the index "i"
transform.position = Vector2.MoveTowards(transform.position, points[i].position, platformSpeed * Time.deltaTime);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (transform.position.y < collision.transform.position.y - 1.3f)
{
collision.transform.SetParent(transform);
}
}
void OnCollisionExit2D(Collision2D collision)
{
collision.transform.SetParent(null);
}
}
评论 (0)