How to merge 4 box colliders into one collider?

Hi everyone!

At the moment i am making a game with a border. I have created 4 box colliders, but was just wondering how
i could mesh these together so i don’t have to have 1 script attached to each of the box collider border

You can put multiple box colliders on a single object.

I have done that, but then the script does not work -

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WorldBorderScript : MonoBehaviour {

    float borderTimer;
    public Transform Player;


    void OnTriggerEnter(Collider other)
    {
        borderTimer = 10;
    }

    void OnTriggerStay(Collider borderCollider)
    {
        borderTimer -= Time.deltaTime;

        if (borderTimer <= 0)
        Player.transform.position = new Vector3(Random.Range(-40, 40), 0.5f, Random.Range(-40, 40));
    }
}

The WorldBorder script only works when its on the boxcollider and not on the parent object

1 Like