I would like to use an offset in this script.

I would like to use an offset in this script.
Please give me an answer.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// © 2017 TheFlyingKeyboard
// theflyingkeyboard.net
//Moves object between two points
public class MoveBetweenTwoPoints : MonoBehaviour {
[SerializeField] private float moveSpeed;
[SerializeField] private GameObject pointA;
[SerializeField] private GameObject pointB;
[SerializeField] private bool reverseMove = false;
[SerializeField] private Transform objectToUse;
[SerializeField] private bool moveThisObject = false;
private float startTime;
private float journeyLength;
private float distCovered;
private float fracJourney;
void Start()
{
startTime = Time.time;
if (moveThisObject)
{
objectToUse = transform;
}
journeyLength = Vector3.Distance(pointA.transform.position, pointB.transform.position);
}
void Update()
{
distCovered = (Time.time - startTime) * moveSpeed;
fracJourney = distCovered / journeyLength;
if (reverseMove)
{
objectToUse.position = Vector3.Lerp(pointB.transform.position, pointA.transform.position, fracJourney);
}
else
{
objectToUse.position = Vector3.Lerp(pointA.transform.position, pointB.transform.position, fracJourney);
}
if ((Vector3.Distance(objectToUse.position, pointB.transform.position) == 0.0f || Vector3.Distance(objectToUse.position, pointA.transform.position) == 0.0f)) //Checks if the object has travelled to one of the points
{
if (reverseMove)
{
reverseMove = false;
}
else
{
reverseMove = true;
}
startTime = Time.time;
}
}
}

(code)(/code) tags required, plus this is a BGE forum, not Unity.

Also the way it is asked is not enjoyable.

Also, a generic offset? What’s that? Offset from what?
Even were this related to BGE, the question does not contain enough information to answer…

You probably need to create another Vector3 depending on whatever you want the offset from, and add it to either the pointA.transform or pointB.transform.

seems like a moving platform?..but it could be anything I guess…I really only looked at one line…so…take this with a grain of salt…

I see, now…yes, this is not unity :slight_smile: I do not want to just shoot you down, but you will get better support from the unity forums…