unity3d 电脑上的左右移动发布到手机上,怎么实现
1个回答
2016-10-28 · 知道合伙人互联网行家
关注
展开全部
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;
}
}
参数要微调下
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;
}
}
参数要微调下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询