2014-01-18 40 views
-5

我有這個long if語句。它給我的錯誤> =操作數不能應用於Bool和Float類型

>= Operand cannot be applied to types Bool and Float

if (tl.State == TouchLocationState.Pressed && 
    (tl.Position.X >= harePlayer.Position.X >= tl.Position.X && 
    tl.Position.Y >= harePlayer.Position.Y && 
    harePlayer.Position.X <= (harePlayer.Position.X + 52) && 
    tl.Position.Y <= (harePlayer.Position.Y + 50))) 

誰能告訴我的解決辦法是什麼呢?謝謝。 :)

+0

無關的,但'harePlayer.Position.X <=(harePlayer.Position.X + 52)'總是真除非harePlayer.Position.X是NaN的。 – Kyle

回答

8

tl.Position.X >= harePlayer.Position.X >= tl.Position.X是不正確的c#條件。你必須寫兩個獨立的條件和合並它們使用&&

tl.Position.X >= harePlayer.Position.X && harePlayer.Position.X >= tl.Position.X 
+1

,請將其重構爲'tl.Position.X == harePlayer.Position.X'(或者我最終丟失了它嗎?) – Stephen

+0

無論如何,它的工作原理和你修復它!非常感謝好友。 :) – Muffin

相關問題