Hey everyone,
Sorry for posting again but I just have alot of trouble with scripting. Anyway I have a problem were I what the ball in my game to reappear in a fixed position. Here’s the code.
public class Ball : MonoBehaviour
{
public float MinSpeed;
public float MaxSpeed;
private float currentSpeed;
private float x, y, z;
// Use this for initialization
void Start ()
{
SetPositionAndSpeed();
}
// Update is called once per frame
void Update ()
{
float amtToMove = currentSpeed * Time.deltaTime;
transform.Translate(Vector3.left * amtToMove);
if(transform.position.x >= -6.5)
{
SetPositionAndSpeed();
}
}
public void SetPositionAndSpeed()
{
currentSpeed = Random.Range(MinSpeed, MaxSpeed);
x = Random.Range(-16f, 16f);
y = 1.2f;
z = 14f;
}
}
If anyone can help that would be great.