//1、 利用层级关系,触碰时,方块是角色的父级,离开解除关系
void OnCollisionStay(Collision other)
{
other.gameObject.transform.parent = transform;
}
void OnCollisionExit(Collision other)
{
other.gameObject.transform.parent = null;
}
//2、利用位移,触碰时,角色的位移和方块移动的位移一样
using UnityEngine;
using System.Collections;
public class Move : MonoBehaviour
{
private Transform juese;
void Update()
{
float distanceX = Input.GetAxis("Horizontal") * Time.deltaTime;
if (juese != null)
{
juese.Translate(distanceX, 0, 0);
}
transform.Translate(distanceX, 0, 0);
}
void OnCollisionStay(Collision other)
{
juese = other.gameObject.transform;
}
void OnCollisionExit(Collision other)
{
juese = null;
}
}
Unity学习_实现人物跟随地板移动
最新推荐文章于 2024-09-01 23:40:15 发布