Ok hello again. It is the same script as before. . .
Now the problem I am having is that the object that is moving keeps tilting, and sometimes gets flung.
Code:
using UnityEngine;
public class MovingScriptTest : MonoBehaviour
{
public Vector3 startPosition;
bool up = true;
void Start()
{
startPosition = transform.position;
}
// Update is called once per frame
void Update()
{
MoveVertical();
}
void MoveVertical()
{
var temp = transform.position;
print(up);
if (up == true)
{
temp.y += (40f * Time.deltaTime);
transform.position = temp;
if (transform.position.y >= 1f)
{
up = false;
}
}
if (up == false)
{
temp.y -= (1f * Time.deltaTime);
transform.position = temp;
if (transform.position.y <= 1f)
{
up = true;
}
}
}
}