<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExtremityScript : MonoBehaviour
{
    //==========================================================================================
    // variables
    //==========================================================================================

    private HingeJoint2D _hingeJoint; //the hingejoint component of the extremity

    private bool _isMoving; //wether the extremity is being dragged, used to show the ui circle
    private GameObject _helpCircle; //the ui circle that is shown when the extremity is being dragged

    private AbstractAnchorScript _anchor; //the anchor this extremity is anchored to

    //==========================================================================================
    // public properties
    //==========================================================================================

    public bool IsMoving
    {
        get { return _isMoving; }
        set
        {
            if (!_isMoving && value)
            {
                _helpCircle = Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/EmptyCircle"));
                _helpCircle.transform.parent = this.transform;
                _helpCircle.transform.position = this.transform.position;
            }
            else if (_isMoving && !value)
            {
                Destroy(_helpCircle);
                _helpCircle = null;
            }

            _isMoving = value;
        }
    }

    public bool IsAnchored { get; private set; }

    //==========================================================================================
    // monobehaviour methods
    //==========================================================================================

    // Use this for initialization
    void Start()
    {
        _hingeJoint = this.GetComponent<HingeJoint2D>();

        if (_hingeJoint.connectedBody != null)
        {
            _hingeJoint.enabled = true;
            IsAnchored = true;
        }
        else
        {
            _hingeJoint.enabled = false;
            IsAnchored = false;
        }
    }

    // Update is called once per frame
    void Update()
    {
        if(IsAnchored && this.transform.position.y < Camera.main.transform.position.y - Camera.main.orthographicSize)
        {
            Debug.Log("extremity unanchored because out of screen");
            UnanchorExtremity();
        }


        // I do not know what this code is good for...
        /*if (_hingeJoint != null)
        {
            if (_hingeJoint.connectedBody != null && IsAnchored == false)
            {
                Debug.Log("case A");
                _hingeJoint.enabled = true;
                IsAnchored = true;
            }
            else if (_hingeJoint.connectedBody == null && IsAnchored == true)
            {
                Debug.Log("case B");
                _hingeJoint.enabled = false;
                IsAnchored = false;
            }
        }*/
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("BonusObject"))
        {
            Debug.Log("Collision with Bonus Object");
            UIManager.Instance.AddScore((int)other.GetComponent<BonusObjectScript>().BonusScore);
            Destroy(other.gameObject);<commit_msg>fixed a levitation bug<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExtremityScript : MonoBehaviour
{
    //==========================================================================================
    // variables
    //==========================================================================================

    private HingeJoint2D _hingeJoint; //the hingejoint component of the extremity

    private bool _isMoving; //wether the extremity is being dragged, used to show the ui circle
    private GameObject _helpCircle; //the ui circle that is shown when the extremity is being dragged

    private AbstractAnchorScript _anchor; //the anchor this extremity is anchored to

    //==========================================================================================
    // public properties
    //==========================================================================================

    public bool IsMoving
    {
        get { return _isMoving; }
        set
        {
            if (!_isMoving && value)
            {
                _helpCircle = Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/EmptyCircle"));
                _helpCircle.transform.parent = this.transform;
                _helpCircle.transform.position = this.transform.position;
            }
            else if (_isMoving && !value)
            {
                Destroy(_helpCircle);
                _helpCircle = null;
            }

            _isMoving = value;
        }
    }

    public bool IsAnchored { get; private set; }

    //==========================================================================================
    // monobehaviour methods
    //==========================================================================================

    // Use this for initialization
    void Start()
    {
        _hingeJoint = this.GetComponent<HingeJoint2D>();

        if (_hingeJoint.connectedBody != null)
        {
            _hingeJoint.enabled = true;
            IsAnchored = true;
        }
        else
        {
            _hingeJoint.enabled = false;
            IsAnchored = false;
        }
    }

    // Update is called once per frame
    void Update()
    {
        if(IsAnchored && this.transform.position.y < Camera.main.transform.position.y - Camera.main.orthographicSize)
        {
            Debug.Log("extremity unanchored because out of screen");
            UnanchorExtremity();
        }


        if(IsAnchored && _hingeJoint.connectedBody == null)
        {
            _hingeJoint.enabled = false;
            IsAnchored = false;
        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("BonusObject"))
        {
            Debug.Log("Collision with Bonus Object");
            UIManager.Instance.AddScore((int)other.GetComponent<BonusObjectScript>().BonusScore);
            Destroy(other.gameObject);
{'fraction_non_alphanumeric': 0.24595109558590028, 'fraction_numerical': 0.0012702445220704986, 'mean_word_length': 2.3117770767613037, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7567643', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1412, 'n_words': 335}