Sup everybody! I’m trying to make a 2d platformer but I’m having trouble making a group of platforms move back and forth continuously. The error I get is “cannot convert ‘UnityEngine.Vector3’ to ‘float’”. I’m new to coding so this is probably a simple fix but I can’t find the answer anywhere!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class platformMove : MonoBehaviour
{
public Transform posA;
public Transform posB;
bool movingForward = true;
float elapsedTime;
public float duration = 2f;
// Update is called once per frame
public void Update()
{
elapsedTime += Time.deltaTime;
if(movingForward)
{
transform.position = Mathf.Lerp(posA.position, posB.position, elapsedTime / duration);
if (elapsedTime >= duration)
{
return;
}
elapsedTime = 0f;
movingForward = false;
}
else
{
transform.position = Mathf.Lerp(posB.position, posA.position, elapsedTime / duration);
if(elapsedTime >= duration)
{
elapsedTime = 0f;
movingForward = true;
}
}
}
}