Hey, so I’ve got a script where a 2D obstacle is supposed to move up and down on a loop. The script works fine, but for a second or two, the obstacle just goes invisible and then comes back. However, it only goes invisible in the game area, not in the scene area. I’m going to attach my code and a video link to show whats happening. Here’s the video: Disappearing Object on Vimeo.
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpikeMovement : MonoBehaviour {
public Transform farEnd;
private Vector3 frometh;
private Vector3 untoeth;
public float secondsForOneLength = 20f;
// Use this for initialization
void Start () {
frometh = transform.position;
untoeth = farEnd.position;
}
// Update is called once per frame
void Update () {
transform.position = Vector3.Lerp(frometh, untoeth,
Mathf.SmoothStep(0f, 1f,
Mathf.PingPong(Time.time / secondsForOneLength, 1f)
));
}
}