Exemple #1
0
    void OnCollisionEnter(Collision collision)
    {
        if (Enabled)
        {
            parcel collidingParcel = collision.gameObject.GetComponent <parcel>();
            if (collidingParcel != null)
            {
                int firstFreeIndex = -1;
                for (int i = 0; i < m_AttachPointParent.childCount; ++i)
                {
                    if (m_ParcelList[i] == null)
                    {
                        firstFreeIndex = i;
                        break;
                    }
                }

                if (firstFreeIndex == -1)
                {
                    return;
                }

                // And parcel to the list and increase the weight
                m_ParcelList[firstFreeIndex] = collidingParcel;
                collidingParcel.SetScaleZone(this);

                m_CurrentWeight += collidingParcel.ParcelWeight;
                m_WeightChanged  = true;

                Transform attachPoint = m_AttachPointParent.GetChild(firstFreeIndex);
                collidingParcel.gameObject.transform.position = attachPoint.position;
                collidingParcel.gameObject.transform.rotation = attachPoint.rotation;

                Rigidbody parcelRigidBody = collidingParcel.GetComponent <Rigidbody>();
                if (parcelRigidBody != null)
                {
                    parcelRigidBody.isKinematic      = true;
                    parcelRigidBody.gameObject.layer = PLAYER_LAYER_IDS[m_PlayerIndex - 1];
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (m_IsStunned)
        {
            return;
        }

        if (Input.GetButtonDown("GrabDrop_P" + m_PlayerNumber))
        {
            if (m_CarriedPackage == false)
            {
                parcel latestPackage = m_Grabber.GetLatestPackage();
                if (latestPackage != null)
                {
                    if (latestPackage.RemovePackageFromZone(m_PlayerIndex))
                    {
                        latestPackage.gameObject.transform.position = m_AttachPoint.position;
                        latestPackage.gameObject.transform.rotation = m_AttachPoint.rotation;
                        latestPackage.gameObject.transform.SetParent(m_AttachPoint);

                        m_CarriedPackage = latestPackage.GetComponent <Rigidbody>();
                        if (m_CarriedPackage != null)
                        {
                            m_CarriedPackage.isKinematic      = true;
                            m_CarriedPackage.gameObject.layer = PLAYER_LAYER_IDS[m_PlayerIndex - 1];
                        }
                    }
                }
            }
            else
            {
                DeparentCarriedPackage();
                m_CarriedPackage = null;
            }
        }
        if (Input.GetButtonDown("Throw_P" + m_PlayerNumber))
        {
            if (m_CarriedPackage != null)
            {
                DeparentCarriedPackage();

                Vector3 throwVector = transform.forward;
                throwVector.x *= m_ThrowSpeedH;
                throwVector.z *= m_ThrowSpeedH;
                throwVector.y  = m_ThrowSpeedV;
                m_CarriedPackage.AddForce(throwVector);

                parcel carriedParcel = m_CarriedPackage.GetComponent <parcel>();
                if (carriedParcel)
                {
                    carriedParcel.ThrownIndex = m_PlayerIndex;
                }

                m_CarriedPackage = null;
            }
            else
            {
                if (m_DashCooldown <= 0)
                {
                    m_DashTimer    = m_DashTimeFrames;
                    m_DashCooldown = m_DashCooldownFrames;

                    m_AudioSource.clip = m_DashClip;
                    m_AudioSource.Play();
                }
            }
        }
    }