Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在精确点向上移动对象-Unity_C#_Unity3d - Fatal编程技术网

C# 无法在精确点向上移动对象-Unity

C# 无法在精确点向上移动对象-Unity,c#,unity3d,C#,Unity3d,我是新来的。下面是我想要实现的场景 我有一个敌人和一座塔。 敌人与塔楼相撞,移动到塔顶逃离。 我无法在塔顶的确切位置移动敌人 这是我的密码: void OnTriggerEnter(Collider collider) { moveY = tf.position.y + 6; //6 is the height of tower tf.Translate(0, moveY, 0, Space.World); } 如果我使用“位置”而不是“平移”,它会移动到塔顶位置,但我想让敌人朝塔顶走去。

我是新来的。下面是我想要实现的场景

我有一个敌人和一座塔。 敌人与塔楼相撞,移动到塔顶逃离。 我无法在塔顶的确切位置移动敌人

这是我的密码:

void OnTriggerEnter(Collider collider) {

moveY = tf.position.y + 6; //6 is the height of tower
tf.Translate(0, moveY, 0, Space.World);

}

如果我使用“位置”而不是“平移”,它会移动到塔顶位置,但我想让敌人朝塔顶走去。使用“平移”会使敌人更靠近底部。请帮我解决这个问题

最可能的问题是您的代码无法识别
tf
。试试这个:

void OnTriggerEnter(Collider collider) 
{

moveY = collider.position.y + 6; //6 is the height of tower
collider.Translate(0, moveY, 0, Space.World);

}

如果碰撞的是gameobject
tf
tf
将是碰撞器。您需要进行if条件检查,以确保碰撞器是
tf

最可能的问题是您的代码无法识别
tf
。试试这个:

void OnTriggerEnter(Collider collider) 
{

moveY = collider.position.y + 6; //6 is the height of tower
collider.Translate(0, moveY, 0, Space.World);

}

如果碰撞的是gameobject
tf
tf
将是碰撞器。您需要进行if条件检查,以确保碰撞器处于
tf

状态。作为旁注,您可能需要尝试answers.unity3d.com。它是专为Unity3D设计的堆栈交换网站。作为旁注,您可能想试试answers.Unity3D.com。它是专门用于Unity3D的堆栈交换站点。