2014-12-07 145 views
-1

我有一個剛體和一個球體的球員,我使用OnCollisionEnter並希望使(球體/ objectB的球員/對象的父母),如果我使用腳本(其中標籤「GameController 「用於玩家和標籤」球體「用於球體)並且將該腳本附加到球體,球體成爲玩家的父母,但是當我將該腳本附加到玩家時,玩家不會成爲球體的父母。任何人都知道如何解決這個問題?使另一個對象的父對象

//script when attached to sphere 
void OnCollisionEnter(Collision col) { 

    Debug.Log ("collision occur"); 
    if(col.gameObject.tag=="player") 
    { 
     col.transform.parent=transform; 
    } 
} 

//script when attached to player 
void OnCollisionEnter(Collision col) { 

    Debug.Log ("collision occur"); 
    if(col.gameObject.tag=="sphere") 
    { 
     col.transform.parent=transform; 
    } 
} 
+0

確保你進入這個'if(col.gameObject.tag ==「sphere」)' – FunctionR 2014-12-07 22:12:05

回答

0

那麼代碼沒有錯我猜你可以確保你在if語句裏面?你可以仔細檢查球體是否有標籤球體,並且你拼寫正確嗎?

+1

它區分大小寫,所以「Sphere」和「sphere」是不同的 – Lefty 2014-12-08 10:33:06

相關問題