public void Init(bool isPaddleRight, IPaddleControls controls) { this.controls = controls; Vector2 pos; isRight = isPaddleRight; if (isPaddleRight) { pos = new Vector2(GameManager.topRight.x, 0); pos -= Vector2.right * transform.localScale.x; sprite = this.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Sprites/alienShip"); } else { pos = new Vector2(GameManager.bottomLeft.x, 0); pos += Vector2.right * transform.localScale.x; sprite = this.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Sprites/spaceShip"); } var collider = this.GetComponent <BoxCollider2D>(); collider.size = sprite.bounds.size; collider.offset = sprite.bounds.center; originalHeight = collider.size.y; height = originalHeight; //Update this paddle's position transform.position = pos; }
// Start is called before the first frame update void Start() { bottomLeft = Camera.main.ScreenToWorldPoint(new Vector2(0, 0)); topRight = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height)); AudioManager.AudioSource = AudioSource; gameBall = Instantiate(ball) as Ball; gameBall.GameManager = this; leftPaddle = Instantiate(paddle) as Paddle; leftPaddle.Init(false, new PlayerControl("PaddleLeft")); rightPaddle = Instantiate(paddle) as Paddle; IPaddleControls controls = null; switch (GameManager.GameType) { case GameType.MULTIPLAYER: controls = new PlayerControl("PaddleRight"); break; case GameType.EASY: controls = new EasyAI(gameBall, rightPaddle); rightPaddle.speed = 4; break; case GameType.MEDIUM: controls = new MediumAI(gameBall, rightPaddle); rightPaddle.speed = 5; break; case GameType.HARD: controls = new HardAI(gameBall, rightPaddle); rightPaddle.speed = 7; break; } rightPaddle.Init(true, controls); leftPaddle.CanMove = false; rightPaddle.CanMove = false; NewGameData(); }