Hi.
I need help with optimize my script. This script enable to my obstacles moving in Y axis between 2 values (0, -4,0) and (0, 4, 0). This script using 10 obstacles at the same time. But this script greatly reduces FPS in my Andorid game.
How can i optimize this code ? Thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BarrierScript : MonoBehaviour
{
float SpeedY = 15;
void Start()
{
}
void Update()
{
transform.position += new Vector3(0f, SpeedY * Time.deltaTime);
if (transform.position.y >= 5.4f)
{
SpeedY *= -1;
}
if (transform.position.y <= -5.4f)
{
SpeedY *= -1;
}
}
}