Ejemplo n.º 1
0
    public void MakeRagdoll(DamageInfo dmg, DeadSoldInitialInfo _inf, bool _playDieVoice)
    {
        Transform rd = (Transform)Instantiate(Ragdoll, gameObject.transform.position, gameObject.transform.rotation);

        DeadSoldierBMW datDeadSoldierBMW = rd.GetComponent <DeadSoldierBMW>();

        datDeadSoldierBMW.InitInitialInfo(_inf);

        if (_playDieVoice)
        {
            datDeadSoldierBMW.SetShouldPlayDieVoice();
        }

        AdvancedRagdoll advRd = rd.GetComponent <AdvancedRagdoll>();

        advRd.SynchRagdollIn(gameObject.transform);

        Destroy(gameObject);

        if (dmg.damageType == DamageType.Bullet)
        {
            AddForceToRagdoll adForce = rd.GetComponent <AddForceToRagdoll>();
            adForce.AddForce(dmg.HitPoint, dmg.BulletDirection, dmg.Impulse);
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (killDelay > 0f)
        {
            killDelay -= Time.deltaTime;
            Debug.Log(killDelay);

            if (killDelay <= 0f)
            {
                // time to kill

                for (int i = 0; i < objectsToKill.Length; ++i)
                {
                    // instantiate ragdolls
                    Transform r = (Transform)Instantiate(ragdollsToCreate[i], objectsToKill[i].transform.position, objectsToKill[i].transform.rotation);

                    if (!r)
                    {
                        Debug.LogError("Example.Update() " + name + " could not Instantiate " + ragdollsToCreate[i].name);
                    }
                    else
                    {
                        // get AdvancedRagdoll script
                        AdvancedRagdoll ar = (AdvancedRagdoll)r.GetComponent("AdvancedRagdoll");

                        if (!ar)
                        {
                            Debug.LogError("Example.Update() " + name + " could not get AdvancedRagdoll from " + r.name);
                        }
                        else
                        {
                            // store ragdoll reference
                            ragdolls.Add(ar);

                            // synch ragdoll to current object animation pose
                            ar.SynchRagdollIn(objectsToKill[i].transform);
                        }
                    }

                    // destroy object
                    Destroy(objectsToKill[i]);
                }
            }
        }
        else if (createDelay > 0f)
        {
            createDelay -= Time.deltaTime;

            if (createDelay <= 0f)
            {
                // time to create

                for (int i = 0; i < ragdolls.Count; ++i)
                {
                    // get AdvancedRagdoll script
                    AdvancedRagdoll ar = ragdolls[i] as AdvancedRagdoll;

                    if (!ar)
                    {
                        Debug.LogError("Example.Update() " + name + " could not get AdvancedRagdoll from ragdolls!");
                    }
                    else
                    {
                        // create new object at the ragdoll's pos/rot
                        Transform newObject = (Transform)Instantiate(objectsToCreate[i], ar.transform.position, ar.transform.rotation);

                        // synch object to ragdoll pose
                        ar.SynchRagdollOut(newObject);

                        // store new object reference
                        objectsToKill[i] = newObject.gameObject;

                        if (!newObject.GetComponent <Animation>())
                        {
                            Debug.LogError("Example.Update() " + name + " has no animation!");
                        }
                        else
                        {
                            // play animation at random start position
                            newObject.GetComponent <Animation>()[objectAnimations[i]].time = Random.Range(0, newObject.GetComponent <Animation>()[objectAnimations[i]].length);
                            newObject.GetComponent <Animation>().CrossFade(objectAnimations[i], 1f);
                        }

                        // destroy ragdoll
                        Destroy(ar.gameObject);
                    }
                }

                // clear ragdoll references
                ragdolls.Clear();

                // re-init timers
                killDelay = createDelay = 5f;
            }
        }
    }