c# - Trying to refine several if statements down -


i'm trying find more elegant way reduce if statements down, have right little messy , reckon done better, suggestions?

        if(ship.position.y >= transform.position.y + ybound)         {             hitbounds = true;         }         if(ship.position.y <= transform.position.y - ybound)         {             hitbounds = true;         }         if(ship.position.x >= transform.position.x + xbound)         {             hitbounds = true;         }         if(ship.position.x <= transform.position.x - xbound)         {             hitbounds = true;         } 

thanks time!

update

if(mathf.abs(ship.position.x - transform.position.x) >= xbound || mathf.abs(ship.position.y - transform.position.y) >= ybound) {     hitbounds = true; } 

worked treat, million!

hitbounds = math.abs(ship.position.x - transform.position.x) >= xbound || math.abs(ship.position.y - transform.position.y) >= ybound; 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -