Hello unity forum heros. I need help. I can’t solve this problem.
using UnityEngine;
public class Background : MonoBehaviour
{
private float move = 10.0f;
private float forTimes, forTimes0 = 30.0f;
private float wait = 0.2f;
private bool positive = true;
private float smooth;
private Transform tf;
void Start()
{
tf = GetComponent<Transform>();
smooth = move / forTimes;
InvokeRepeating("BackgroundMove", wait, wait);
}
private void BackgroundMove()
{
if (forTimes > 0)
{
print("selam");
tf.position = new Vector3(tf.position.x, tf.position.y + smooth); // HERE
print(tf.position);
forTimes--;
}
else if (forTimes < 0)
{
if (forTimes > 0)
forTimes *= -1;
tf.position.Set(tf.position.x, tf.position.y + smooth, tf.position.z); ;
forTimes++;
}
else
{
if (positive)
{
forTimes = -1 * forTimes0;
positive = !positive;
}
else
{
forTimes = forTimes0;
positive = !positive;
}
}
}
}