okay so, i’m following a 1 because i’m doing the same project for my exam next week, and i can’t seem to make the platform move as it should.
here’s what i’ve got:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class plataformaascendente : MonoBehaviour
{
float velocidadPlataforma = 2;
bool puntoLLegada;
float puntoPartida;
float puntoLLegadaY;
public int unidadesaMover;
// Use this for initialization
void Start()
{
puntoPartida = transform.position.y ;
puntoLLegadaY = puntoPartida + unidadesaMover;
}
// Update is called once per frame
void Update()
{
if (puntoLLegada)
{
transform.position += Vector3.up * velocidadPlataforma * Time.deltaTime;
}
else
{
transform.position -= Vector3.up * velocidadPlataforma * Time.deltaTime;
}
if (transform.position.y >= puntoLLegadaY)
{
puntoLLegada = false;
}
if (transform.position.y <= puntoLLegadaY)
{
puntoLLegada = true;
}
}
}
again, i’m sorry about the spanish, and thanks for taking the time to read through this!
okay, someone already helped me, this is what worked:
public float speed;
public float distance;
public float downLimit;
public float upLimit;
public int dir = 1;
public float PositionActual;
public float PosicionStart;
void Start()
{
PosicionStart = transform.position.y;
downLimit = PosicionStart - distance;
upLimit = PosicionStart + distance;
speed = 5;
}
void Update()
{
PositionActual = transform.position.y;
transform.position += Vector3.up * speed * Time.deltaTime * dir;
if (PositionActual > upLimit)
{
dir = -1;
GetComponent<SpriteRenderer>().flipX = false;
}
else if (PositionActual < downLimit)
{
dir = 1;
GetComponent<SpriteRenderer>().flipX = true;
}
}