2016-06-11 35 views
0

我正在製作一款遊戲,就像一名消防員,這裏是玩家必須通過布來撲滅火焰的場景,我已經成功製作了一塊布,而且我可以挑選它,但是當我扔它,它不會扔,它仍然存在。 在這裏,我想扔布在火(特定距離)。這是我迄今爲止所做的代碼。任何建議,問題在哪裏?或者該怎麼辦?在特定距離拋出物品

using UnityEngine; 
using System.Collections; 
public class pickup : MonoBehaviour { 
public Transform OnHand; 
// Use this for initialization 
void Start() { 

} 

// Update is called once per frame 
void Update() { 
    if (Input.GetButtonDown ("E")) { 
     GetComponent<Rigidbody>().useGravity=false; 
     this.transform.position = OnHand.position; 
     this.transform.parent = GameObject.Find ("FPSController").transform; 
     this.transform.parent = GameObject.Find ("FirstPersonCharacter").transform; 

    }   
    if (Input.GetMouseButtonDown (0)) { 
     this.transform.parent = null; 
     GetComponent<Rigidbody>().useGravity=false; 
//  Rigidbody.AddForce (new Vector2(1,4), ForceMode.Impulse); 
    } 
} 
} 

回答

0

看起來像你有一切非常正確。您正確地提到了剛體,以關閉重力,但後來嘗試不正確地引用剛體以增加力度。

做GetComponent()。AddForce(new Vector2(1,4),ForceMode.Impulse);

我不明白爲什麼不行。當然拿出'//'。 另外,爲了優化目的,您可以在清醒或啓動時存儲剛體,而不是使用變量而不是多次使用GetComponent。

類似rb = GetComponent(); 然後你可以使用rb.AddForce()。

希望它有幫助!如果確實如此,如果您可以將其標記爲正確答案並註冊成功,那麼其他人會知道它已被回答:)。