private void Update() { /// Movements if (Input.GetKey(KeyCode.S)) // bottom { currentDirection |= Enums.MovementDirection.BOTTOM; if ((blockedDirections & Enums.MovementDirection.BOTTOM) != 0) { rgdBody.velocity = new Vector2(rgdBody.velocity.x, 0); } else { rgdBody.velocity = new Vector2(rgdBody.velocity.x, -unitInfos.getVitesse()); } } else if (Input.GetKey(KeyCode.Z)) // top { currentDirection |= Enums.MovementDirection.TOP; if ((blockedDirections & Enums.MovementDirection.TOP) != 0) { rgdBody.velocity = new Vector2(rgdBody.velocity.x, 0); } else { rgdBody.velocity = new Vector2(rgdBody.velocity.x, unitInfos.getVitesse()); } } else if (rgdBody.velocity.y < 0.25f && rgdBody.velocity.y > -0.25f) { rgdBody.velocity = new Vector2(rgdBody.velocity.x, 0); } else if (rgdBody.velocity.y > 0) { rgdBody.velocity = new Vector2(rgdBody.velocity.x, rgdBody.velocity.y - (float)(unitInfos.baseVitesse / unitInfos.coeffFreinage)); } else if (rgdBody.velocity.y < 0) { rgdBody.velocity = new Vector2(rgdBody.velocity.x, rgdBody.velocity.y + (float)(unitInfos.baseVitesse / unitInfos.coeffFreinage)); } if (Input.GetKey(KeyCode.D)) // right { currentDirection |= Enums.MovementDirection.RIGHT; if ((blockedDirections & Enums.MovementDirection.RIGHT) != 0) { rgdBody.velocity = new Vector2(0, rgdBody.velocity.y); } else { rgdBody.velocity = new Vector2(unitInfos.getVitesse(), rgdBody.velocity.y); } } else if (Input.GetKey(KeyCode.Q)) // left { currentDirection |= Enums.MovementDirection.LEFT; if ((blockedDirections & Enums.MovementDirection.LEFT) != 0) { rgdBody.velocity = new Vector2(0, rgdBody.velocity.y); } else { rgdBody.velocity = new Vector2(-unitInfos.getVitesse(), rgdBody.velocity.y); } } else if (rgdBody.velocity.x < .25f && rgdBody.velocity.x > -.25f) { rgdBody.velocity = new Vector2(0, rgdBody.velocity.y); } else if (rgdBody.velocity.x > 0) { rgdBody.velocity = new Vector2(rgdBody.velocity.x - (float)(unitInfos.baseVitesse / unitInfos.coeffFreinage), rgdBody.velocity.y); } else if (rgdBody.velocity.x < 0) { rgdBody.velocity = new Vector2(rgdBody.velocity.x + (float)(unitInfos.baseVitesse / unitInfos.coeffFreinage), rgdBody.velocity.y); } /// Colors management if (unitInfos.vitesseModifier < 100f && unitInfos.vitesseModifier != 0f) { spriteRenderer.color = Colors.slow; } else { spriteRenderer.color = Colors.normal; } /// Shoot if (Input.GetKey(KeyCode.M)) // right { bulletFactory.Shoot(rgdBody, unitInfos, gameObject, "right"); } else if (Input.GetKey(KeyCode.K)) // left { bulletFactory.Shoot(rgdBody, unitInfos, gameObject, "left"); } else if (Input.GetKey(KeyCode.O)) // up { bulletFactory.Shoot(rgdBody, unitInfos, gameObject, "top"); } else if (Input.GetKey(KeyCode.L)) // bottom { bulletFactory.Shoot(rgdBody, unitInfos, gameObject, "bottom"); } /// Check movements if (Input.GetKeyUp(KeyCode.S)) { currentDirection &= ~Enums.MovementDirection.BOTTOM; } if (Input.GetKeyUp(KeyCode.Z)) { currentDirection &= ~Enums.MovementDirection.TOP; } if (Input.GetKeyUp(KeyCode.Q)) { currentDirection &= ~Enums.MovementDirection.LEFT; } if (Input.GetKeyUp(KeyCode.D)) { currentDirection &= ~Enums.MovementDirection.RIGHT; } }