2017-01-23 133 views
0

我试图在按下Input时从父对象(即像一个球)抛出一个特定的子对象。我已经让我的球员拿起一个球并将它作为它自己的一个小孩(并随着它移动),但是我无法获得投掷功能的效果。这里是我的代码:请注意Update函数中的'/////',那是我相信代码会去的地方?我可能是错的。我已经尝试了几件事情无济于事。Unity C# - 从父对象中抛出一个子对象

public static float playerDistance; 
bool hasGarbage; 

// Update is called once per frame 
void Update() { 

    float h = Input.GetAxis("Horizontal"); 
    transform.Translate(h * Time.deltaTime * 5f, 0f, 5f * Time.deltaTime); 
    playerDistance = transform.localPosition.z; 


    if (hasGarbage == true) 
    { 
     if (Input.GetButtonDown("Fire1")) 
     { 
      //////////////////////////////////////////////////// 

     } 
    } 

} 

private void OnTriggerEnter(Collider other) 
{ 
    if (other.tag == "Garbage") 
    { 

     other.transform.parent = transform; 
     hasGarbage = true; 


    } 
} 

}

+2

你应该考虑建立一个[固定接头(https://docs.unity3d.com/手动/ class-FixedJoint.html),而不是实际上在球员下方养育球。当你需要抛球时,在施加任何力量之前先断开关节。 – Serlite

回答

相关问题