void Update() { if (_invulnerabilityTimer > 0) { IsInvulnerable = true; _invulnerabilityTimer -= Time.deltaTime; } else { IsInvulnerable = false; } if (IsInvulnerable) { float r = 1 - ((0.5f * Mathf.Sin(_invulnerabilityTimer * InvulnerableFlashSpeed)) + 0.5f); GetComponent <SpriteRenderer>().color = new Color(r, 1, 1, 1); } else { GetComponent <SpriteRenderer>().color = Color.white; } if (Control == GameManager.Control.PLAYER_ONE) { Vector2 move = new Vector2(0, Input.GetAxisRaw("P1GoalVertical")).normalized *Acceleration; GetComponent <Rigidbody2D>().AddForce(move, ForceMode2D.Force); } else if (Control == GameManager.Control.PLAYER_TWO) { Vector2 move = new Vector2(0, Input.GetAxisRaw("P2GoalVertical")).normalized *Acceleration; GetComponent <Rigidbody2D>().AddForce(move, ForceMode2D.Force); } else if (Control == GameManager.Control.AI) { GameManager.Quadrant q = GameManager.Instance.GetPuckQuadrant(); if (q == GameManager.Quadrant.TOPLEFT || q == GameManager.Quadrant.TOPRIGHT) { GetComponent <Rigidbody2D>().AddForce(new Vector2(0, -1 * Acceleration), ForceMode2D.Force); } else { GetComponent <Rigidbody2D>().AddForce(new Vector2(0, Acceleration), ForceMode2D.Force); } } }
void Update() { if (Control == GameManager.Control.PLAYER_ONE) { Vector2 move = new Vector2(Input.GetAxisRaw("P1MalletHorizontal"), Input.GetAxisRaw("P1MalletVertical")).normalized *Acceleration; GetComponent <Rigidbody2D>().AddForce(move, ForceMode2D.Force); } else if (Control == GameManager.Control.PLAYER_TWO) { Vector2 move = new Vector2(Input.GetAxisRaw("P2MalletHorizontal"), Input.GetAxisRaw("P2MalletVertical")).normalized *Acceleration; GetComponent <Rigidbody2D>().AddForce(move, ForceMode2D.Force); } else if (Control == GameManager.Control.AI) { if (GameManager.Instance.GamePuck) { GameManager.Quadrant q = GameManager.Instance.GetPuckQuadrant(); if (q == GameManager.Quadrant.TOPRIGHT || q == GameManager.Quadrant.BOTTOMRIGHT) { //transform.position = transform.position + (GameManager.Instance.GamePuck.transform.position - transform.position).normalized * MaxSpeed * Time.deltaTime; Vector3 move = (GameManager.Instance.GamePuck.transform.position - transform.position).normalized * Acceleration; GetComponent <Rigidbody2D>().AddForce(new Vector2(move.x, move.y)); } else { Goal g = GameManager.Instance.GetCorrespondingGoal(this); if (Side == GameManager.Side.RIGHT) { Vector3 move = ((g.transform.position - new Vector3(2, 0, 0)) - transform.position).normalized * Acceleration; GetComponent <Rigidbody2D>().AddForce(new Vector2(move.x, move.y)); } } } } }