예제 #1
0
    public virtual void DropTopCrate()
    {
        Dropping = true;
        Vector3 origin = transform.position + Vector3.up * transform.localScale.y * 0.5f;

        RaycastHit hit;

        if (Physics.Raycast(origin, Vector3.up, out hit, transform.localScale.y))
        {
            Crate nextCrate = hit.transform.GetComponent <Crate> ();

            if (nextCrate != null && nextCrate.canDrop)
            {
                Rigidbody rigidbody = hit.transform.gameObject.GetComponent <Rigidbody> ();
                if (rigidbody == null)
                {
                    rigidbody = hit.transform.gameObject.AddComponent <Rigidbody> ();
                }

                rigidbody.constraints = RigidbodyConstraints.FreezePositionX |
                                        RigidbodyConstraints.FreezePositionZ |
                                        RigidbodyConstraints.FreezeRotation;

                nextCrate.Dropping = true;
                nextCrate.OnDropStart();
                nextCrate.DropTopCrate();
            }
        }
    }