This is my first ever game I am making so maybe my question is going to be silly.
i have like 50 obstacle objects in the scene and i want them to share a script which moves them from left to right.
//here is my code for movements
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sidemove : MonoBehaviour
{
public float sideForce;
public Rigidbody rbo;
public Transform tr;
// Use this for initialization
void Start ()
{
rbo.AddForce(sideForce * Time.deltaTime,0,0);
}
// Update is called once per frame
void Update () {
if(rbo.position.x==-10)
{
rbo.AddForce(-sideForce * Time.deltaTime, 0, 0);
}
if (rbo.position.x == 10)
{
rbo.AddForce(sideForce * Time.deltaTime, 0, 0);
}
}
}
Note: all obstacles are placed at different x,y,z position throughout the ground and they share the same script.
Pls help me with this . Thanks in advance