コード例 #1
0
ファイル: ShapePieces.cs プロジェクト: mitjaimmonen/H-O-M-E
 void OnTriggerEnter2D(Collider2D col)
 {
     if (AllowControl && col.gameObject.GetComponent <ShapePieces>() != null)
     {
         ShapePieces piece     = col.gameObject.GetComponent <ShapePieces>();
         float       magnitude = ((Vector2)col.transform.position - (Vector2)transform.position).magnitude;
         if (magnitude < attractDistance)
         {
             piece.GetAttracted(this, magnitude / attractDistance * attractForce);
         }
     }
 }
コード例 #2
0
    void OnTriggerStay2D(Collider2D col)
    {
        if (Occupied)
        {
            return;
        }

        ShapePieces piece = col.GetComponentInParent <ShapePieces>();

        if (piece)
        {
            float magnitude = ((Vector2)col.transform.position - (Vector2)transform.position).magnitude;
            if (magnitude < snapDistance && Quaternion.Angle(transform.rotation, piece.transform.rotation) < 10f)
            {
                piece.SnugFit(this);
            }
            else if (magnitude < attractDistance)
            {
                piece.GetAttracted(this, ((attractDistance - magnitude) / attractDistance) * attractForce, magnitude / attractDistance);
            }
        }
    }