【发布时间】:2018-07-02 20:02:54
【问题描述】:
所以我有these 两个圈子。白色的应该在它转向的方向上从有色的那个跳开。它有时会起作用,但有时会以错误的角度跳跃或几乎不移动。这是我的代码:
void Update () {
if (Input.GetKeyDown(KeyCode.Space)) {
jumpDirection = transform.parent.rotation * Vector3.up;
transform.parent = null;
go1.AddComponent();
go2.AddComponent();
}
if(transform.parent == null) {
Vector3 rrotation = jumpDirection;
transform.Translate(rrotation * Time.deltaTime, Space.World);
}
}
void OnCollisionEnter2D(Collision2D col) {
if (col.collider.tag == "sun") {
Destroy(gameObject);
}
if(col.collider.tag == "border") {
Destroy(gameObject);
}
transform.SetParent(col.gameObject.transform);
transform.rotation = transform.parent.rotation;
}
我在移动设备上,如果格式有点不对,请见谅。有谁知道如何解决这个问题?
【问题讨论】:
-
对你的游戏对象使用 transform.forward。