I’m trying to make walls spawn and move towards my player across a plane, but the force doesn’t affect the walls at all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObstacleSpawner : MonoBehaviour {
public GameObject[] Obstacles;
public float wallSpeed;
private float Timer;
private int spawnIndex;
private Rigidbody rb;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Timer += Time.deltaTime;
if(Timer >= 2)
{
spawnIndex = Random.Range(0, Obstacles.Length);
Instantiate(Obstacles[spawnIndex]);
Obstacles[spawnIndex].GetComponent<Rigidbody>();
rb.AddForce(0, 0, wallSpeed);
Timer = 0;
}
}
}