I’m trying to make a simple moving platform script using c#. The following code is based on someone else’s code that was done in javascript. i tried to replicate it in c# but I get the cs1612 error. any help is appreciated.
private float platform_x;
private float platform_y;
private bool max;
public bool vert;
public int maxAmount;
public float step;
// Use this for initialization
void Start () {
platform_x = transform.position.x; //setting up the initial value
platform_y = transform.position.y;
}
// Update is called once per frame
void Update ()
{
//SET THE MAX
if (vert) {
if (transform.position.y >= platform_y + maxAmount) {
max = true;
} else if (transform.position.y <= platform_y) {
max = false;
}
} else{//Horizontal
if (transform.position.x >= platform_x + maxAmount) {
max = true;
} else if (transform.position.x <= platform_x) {
max = false;
}
// MOVING THE PLATFORM
if (vert) {
if (!max) {
transform.position.y += step;
} else {
transform.position.y -= step;
}
} else {
if (!max) {
transform.position.x += step;
} else {
transform.position.x -= step;
}
}
}