Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        calculatedVelocity = (transform.position - lastPosition) * 100f;
        if (GetGrab())
        {
            if (!grabbingSomething)
            {
                tryingToGrabSomething = true;
            }
            if (grabbingSomething)
            {
                grabbedObject.beingHeld    = true;
                grabbedObject.holderObject = transform;
            }
        }
        else
        {
            tryingToGrabSomething = false;
            if (grabbedObject)
            {
                grabbedObject.beingHeld = false;
                grabbedObject.GetComponent <Rigidbody>().AddForce(calculatedVelocity, ForceMode.VelocityChange);
                grabbedObject.holderObject = null;
                grabbedObject     = null;
                grabbingSomething = false;
            }
        }

        lastPosition = transform.position;
    }
Ejemplo n.º 2
0
 private void OnTriggerStay(Collider other)
 {
     if (other.gameObject.GetComponent <modularGrabObject>() && tryingToGrabSomething && !grabbingSomething && other.gameObject.GetComponent <modularGrabObject>().canHold)
     {
         grabbedObject = other.gameObject.GetComponent <modularGrabObject>();
         grabbedObject.holderObject = this.transform;
         grabbedObject.beingHeld    = true;
         grabbingSomething          = true;
     }
 }