I’m making a script for this blimp to slowly go up and down in the background. I assign its max height and min height in the Start() method. The script doesn’t work right. When I print the variables using Debug.Log(), I can see the max and min height variables changing values even though they are not being assigned in the Update function. Here is the code:
// Use this for initialization
void Start ()
{
// Height variation = 50
// transform.position = -10, 100, 192
maxPos = transform.position + new Vector3(0, 0, heightVariation);
minPos = transform.position - new Vector3(0, 0, -heightVariation);
destination = maxPos;
speed /= 100;
}
// Update is called once per frame
void Update ()
{
Debug.Log("Max: " + maxPos);
Debug.Log("Min: " + minPos);
if (goingUp)
{
transform.Translate(0, 0, speed);
if (Mathf.Abs(Vector3.Distance(transform.position, maxPos)) < speed/2)
{
goingUp = false;
transform.Translate(0, 0, -speed);
}
}
else
{
transform.Translate(0, 0, -speed);
if (Mathf.Abs(Vector3.Distance(transform.position, minPos)) < speed / 2)
{
goingUp = true;
transform.Translate(0, 0, speed);
}
}
}
This picture shows what I mean. The values of Max and Min change between 217 and 242.
I’m not sure what’s going on here. Any help would be appreciated. Thanks!