Exemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Pillow")
        {
            Pillow incomingPillow = other.GetComponent <Pillow>();

            // getting hit by a pillow
            if (incomingPillow.IsThrown)
            {
                Debug.Log("abc");
                if (incomingPillow.Owner != this)
                {
                    //player is hit
                    Debug.Log("Child is hit by a pillow");

                    if (!ReceiveSound.isPlaying)
                    {
                        ReceiveSound.Play();
                    }

                    Push(other.GetComponent <Rigidbody>().velocity.normalized * 10 * hitPushBackForce);
                    Destroy(other.gameObject);
                }
            }
            // picking up a pillow
            else if (this.pillow == null && incomingPillow.IsPickable)
            {
                //Debug.Log("def");
                pillow = incomingPillow;

                pillow.transform.parent = transform;                  // make the pillow a child of Child
                pillow.gameObject.SetActive(false);
                pillow.GetComponent <Rigidbody>().isKinematic = true; // dont make pillow obey to gravity when in a child's hands
                pillow.IsOwned = true;
                pillow.Owner   = this;
                AnimationPillow.SetActive(true);

                // TODO: place the pillow correctly or animate or something...
            }
        }
    }
Exemplo n.º 2
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Pillow"){

            Pillow incomingPillow = other.GetComponent<Pillow>();

            // getting hit by a pillow
            if (incomingPillow.IsThrown) {
                Debug.Log("abc");
                if (incomingPillow.Owner != this)
                {
                    //player is hit
                    Debug.Log("Child is hit by a pillow");

                    if (!ReceiveSound.isPlaying)
                    {
                        ReceiveSound.Play();
                    }

                    Push(other.GetComponent<Rigidbody>().velocity.normalized * 10 * hitPushBackForce);
                    Destroy(other.gameObject);
                }
            }
            // picking up a pillow
            else if (this.pillow == null && incomingPillow.IsPickable) {
                //Debug.Log("def");
                pillow = incomingPillow;

                pillow.transform.parent = transform; // make the pillow a child of Child
                pillow.gameObject.SetActive(false);
                pillow.GetComponent<Rigidbody>().isKinematic = true; // dont make pillow obey to gravity when in a child's hands
                pillow.IsOwned = true;
                pillow.Owner = this;
                AnimationPillow.SetActive(true);

                // TODO: place the pillow correctly or animate or something...
            }
        }
    }