Question by
mirbatis · Nov 18, 2018 at 03:42 PM ·
scripting problempong
Borders problem Paddles Pong
I'm having trouble having the Paddles stop in my Pong game when they hit the borders of the game, they freeze and don't move again. (The total size of my game layout is height which is altoMundo = 6 and width which anchoMundo = 8.)
public KeyCode up, down;
public float speed;
public const float altoMundo = 6;
public const float anchoMundo = 8;
private float topearriba = 3.4f;
private float topeabajo = -1.4f;
float incrY = 0.1f;
private float width, height;
private float limitY;
private Vector3 startposition;
void Start () {
Renderer renderer = GetComponent<Renderer>();
Vector3 size = renderer.bounds.size;
height = size.y;
width = size.x;
startposition = transform.position;
}
void Update () {
if (Input.GetKey(up))
{
transform.Translate(0.0f, speed, 0.0f);
while (transform.position.y + speed >= topearriba)
speed = -speed;
}
if (Input.GetKey(down))
{
transform.Translate(0.0f, -speed, 0.0f);
while (transform.position.y + speed <= topeabajo)
speed = -speed;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612182334im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[SOLVED]My code line don't execute 1 Answer
Why isn't this script posting the score to Google Play Leaderboards? 2 Answers
Setting string to 'entire' contents of input field? 0 Answers
An object reference is required to access non-static member (CS0120) 1 Answer
Problem with saving player data 0 Answers