C# Unity 2D c“目标位置出现的对象不是”;“勒平”;
我不明白为什么这个脚本会导致对象跳转到目标,而不是平滑地移动到目标C# Unity 2D c“目标位置出现的对象不是”;“勒平”;,c#,unity3d,C#,Unity3d,我不明白为什么这个脚本会导致对象跳转到目标,而不是平滑地移动到目标 public GameObject Hand; public GameObject projectile; void OnCollisionStay2D (Collision2D coll) { if (Input.GetKeyDown (KeyCode.E)) { if (coll.gameObject.tag == "Pickup") { if (Hand.t
public GameObject Hand;
public GameObject projectile;
void OnCollisionStay2D (Collision2D coll)
{
if (Input.GetKeyDown (KeyCode.E)) {
if (coll.gameObject.tag == "Pickup") {
if (Hand.transform.childCount < 1) {
coll.gameObject.transform.position = Hand.transform.position;
coll.gameObject.transform.parent = Hand.transform;
projectile = coll.gameObject;
//coll.gameObject.name = "Projectile";
}
}
}
}
void Update ()
{
if (Input.GetMouseButtonDown (1)) {
if (Hand.transform.childCount == 1) {
projectile.transform.rotation = Hand.transform.rotation;
projectile.gameObject.transform.parent = null;
float shotDistance = 3;
float time = 3;
projectile.transform.Translate(Vector3.Lerp (Hand.transform.position,Vector3.up * shotDistance,time));
}
}
}
公共游戏对象手;
公共游戏对象投射物;
无效碰撞Stay2D(碰撞2D coll)
{
if(Input.GetKeyDown(KeyCode.E)){
如果(coll.gameObject.tag==“拾取”){
if(Hand.transform.childCount<1){
coll.gameObject.transform.position=Hand.transform.position;
coll.gameObject.transform.parent=Hand.transform;
射弹=coll.gameObject;
//coll.gameObject.name=“射弹”;
}
}
}
}
无效更新()
{
if(Input.GetMouseButtonDown(1)){
if(Hand.transform.childCount==1){
射弹.transform.rotation=手.transform.rotation;
sproject.gameObject.transform.parent=null;
浮射距离=3;
浮动时间=3;
投射物.变换.平移(Vector3.Lerp(手.变换.位置,Vector3.up*拍摄距离,时间));
}
}
}
非常感谢您的帮助
谢谢,如果您查看的签名,您会注意到您传递的浮点值为3
浮动应在0-1之间,0.5为中间值 谢谢Scott,这仍然会导致它出现在目的地而不是移动到目的地?您介意更新代码吗?更容易弄清楚