Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to make a Collider usable by Effector via Script

Discussion in '2D' started by Fe0dor, Apr 30, 2022.

  1. Fe0dor

    Fe0dor

    Joined:
    Jan 18, 2020
    Posts:
    17
    Hi,

    basically I want to add a spherecollider component to a gameobject if a certain condition is met and I want that spherecollider component to be used by an effector.

    I cant find a way to enable it through script and I really dont wanna use a collider that is enabled once the condition is met.


    Code (CSharp):
    1.  
    2. SphereCollider = sc;
    3.  
    4. void Something happens ()
    5.     {
    6.  
    7.         sc = gameObject.AddComponent(typeof(SphereCollider)) as SphereCollider;
    8.  
    9.         sc.center = gameObject.transform.position;
    10.         sc.radius = 4;
    11.         sc.isTrigger = true;
    12.         // set to be usable by effector
    13.  
    14.  
    15.  
    16.     }
    17.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    This is the 2D forum but I see you using
    SphereCollider
    ... that is a 3D Physics Component.

    Do you intend to use CircleCollider2D?
     
    Fe0dor likes this.
  3. Fe0dor

    Fe0dor

    Joined:
    Jan 18, 2020
    Posts:
    17
    That would be it thank you and excuse me and my smooth brain
     
    Kurt-Dekker likes this.