Hello everybody,
i´ve found another solution and wanted to ask if Mathf.PingPong has any disadvantage?
It works fine the only difference I guess is that it doesn´t move that smooth and it is only one line of code.
Thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[DisallowMultipleComponent]
public class Oscilator : MonoBehaviour {
[SerializeField] Vector3 movementVector;
[Range(0, 1)][SerializeField]float movementFactor;
Vector3 startingPos;
// Use this for initialization
void Start () {
startingPos = transform.position;
}
// Update is called once per frame
void Update () {
Vector3 offset = movementVector * movementFactor;
transform.position = startingPos + offset;
movementFactor = Mathf.PingPong(Time.time/6, 1); // <<<<< PingPong
}
}