コード例 #1
0
    /**
     * Function that controls the movement of the objects
     * the touch object is interacting with.
     */
    private void MoveObject()
    {
        // Referencing the needed controllers and components
        TouchableObjectController touchableObjectController = touchableObject.GetComponent <TouchableObjectController>();
        Transform   touchableObjectTransform = touchableObject.GetComponent <Transform>();
        Rigidbody2D touchableObjectRb        = touchableObject.GetComponent <Rigidbody2D>();

        /**
         * First checks if the meteorite is currenty being interacted with,
         * and if the meteorite HAS NOT already been touched.
         */
        if (touchableObjectController.IsTouching() && touchableObjectController.touchCount >= 0)
        {
            // Calculating the force of the flick using the modifiable multiplier and speed of touch object
            speed *= 2;
            float flickForce = touchController.flickForceMultiplier * speed;

            // Limits the max force allowed
            // To allow higher touch sensitivity, but not a huge force
            if (flickForce > touchController.maxFlickForce)
            {
                flickForce = touchController.maxFlickForce;
            }

            // Finally, applies the force to the meteorite towards the position of the touch object
            touchableObjectRb.AddForce((transform.position - touchableObjectTransform.position) * flickForce);
            touchableObjectRb.AddTorque((transform.position.x - touchableObjectTransform.position.x) * spinForce);
        }
    }
コード例 #2
0
    /**
     * Assigns the touch object with a touchable object
     * to interact with.
     * Also sets the touchable object in a touched state so that
     * it cannot be interacted with again after the swipe.
     */
    private void SetTouched(Collider2D other)
    {
        // Gets reference to the collided object to obtain the script
        touchableObject = other.gameObject;
        TouchableObjectController touchableObjectController = touchableObject.GetComponent <TouchableObjectController>();

        // Apply the SetTouched function to the object that has been touched
        if (!touchableObjectController.IsTouching())
        {
            touchableObjectController.SetTouched(gameObject);
        }
    }