Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

How to merge 4 box colliders into one collider?

Discussion in 'Physics' started by Deleted User, Jan 24, 2017.

  1. Deleted User

    Deleted User

    Guest

    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

    upload_2017-1-24_22-47-20.png


    upload_2017-1-24_22-47-34.png
     
  2. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    You can put multiple box colliders on a single object.
     
  3. Deleted User

    Deleted User

    Guest

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

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class WorldBorderScript : MonoBehaviour {
    6.  
    7.     float borderTimer;
    8.     public Transform Player;
    9.  
    10.  
    11.     void OnTriggerEnter(Collider other)
    12.     {
    13.         borderTimer = 10;
    14.     }
    15.  
    16.     void OnTriggerStay(Collider borderCollider)
    17.     {
    18.         borderTimer -= Time.deltaTime;
    19.  
    20.         if (borderTimer <= 0)
    21.         Player.transform.position = new Vector3(Random.Range(-40, 40), 0.5f, Random.Range(-40, 40));
    22.     }
    23. }
    24.  
     
  4. Deleted User

    Deleted User

    Guest

    The WorldBorder script only works when its on the boxcollider and not on the parent object
     
    Perun likes this.