how I change this C code for 2D
how I change this C code for 2D
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [RequireComponent(typeof(Collider))]
 public class GravityMatrix : MonoBehaviour
 {
 
     [Range(-100f, 100f)] [SerializeField] float gForceMul = 5f;
 
     void OnTriggerStay(Collider other)
     {
         if (other.gameObject.GetComponent<Rigidbody>() == null)
             return;
 
         GameObject otherOb = other.gameObject;
         Rigidbody otherRb = otherOb.GetComponent<Rigidbody>();
         Transform otherTr = otherOb.GetComponent<Transform>();
 
         Vector3 moveF = transform.position - otherTr.position;
 
         otherRb.AddForce(moveF * gForceMul);
     }
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by donutLaserDev · Mar 15, 2018 at 02:57 PM
Change Rigidbody to Rigidbody2D, OnTriggerStay to OnTriggerStay2D, Collider to Collider2D. Other than that, depends on what you are trying to do.
thenx
using System.Collections; using System.Collections.Generic; using UnityEngine;
[RequireComponent(typeof(Collider2D))] public class Gravity$$anonymous$$atrix : $$anonymous$$onoBehaviour {
 [Range(-100f, 100f)] [SerializeField] float gForce$$anonymous$$ul = 5f;
 void OnTriggerStay2D(Collider2D other)
 {
     if (other.gameObject.GetComponent<Rigidbody2D>() == null)
         return;
     GameObject otherOb = other.gameObject;
     Rigidbody2D otherRb = otherOb.GetComponent<Rigidbody2D>();
     Transform otherTr = otherOb.GetComponent<Transform>();
     Vector2 moveF = transform.position - otherTr.position;
     otherRb.AddForce(moveF * gForce$$anonymous$$ul);
 }
 
                  }
Your answer