示例#1
0
    //TODO: create states for beingHeld, notBeingHeld


    public override void Pickup(GameObject holdPosition)
    {
        Debug.Log("pick battery up. move to: " + holdPosition.name);
        ChangeLayersRecursively(this.transform, "Holding");
        this.GetComponent <Lerping>().oldHeldObject = this.GetComponent <Lerping>().lerpToObject;
        this.GetComponent <Lerping>().lerpToObject  = holdPosition;

        if (this.GetComponent <Lerping>().inBatteryHolder == true)
        {
            Debug.Log("has battery");
            GameObject oldHeldObject = this.GetComponent <Lerping>().oldHeldObject;
            if (oldHeldObject)
            {
                // call animation
                //TODO fix this
                Animate animate = oldHeldObject.GetComponent <SnapTrigger>().activateObject.GetComponent <Animate>();
                if (animate)
                {
                    animate.Animation();
                }

                //stop sound
                //TODO fix this
                AudioSource audio = oldHeldObject.GetComponent <AudioSource>();
                if (audio)
                {
                    audio.Stop();
                }
            }

            this.GetComponent <Lerping>().inBatteryHolder = false;
        }

        this.GetComponent <Lerping>().StartLerp(true);

        this.transform.localPosition = Vector3.zero;
        this.transform.localRotation = Quaternion.identity;
        this.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotation;
    }