コード例 #1
0
 //Called from either ApplyDecal or ApplyDent; same as BulletSound except it plays the set's collision sound instead of its bullet sound
 public void CollisionSound(HitEffectArray info)
 {
     //The info array has hit.point, hitRotation, hit.transform, hit.normal, hitSet
     if (setArray[info.hitSet].collisionSounds[0] != null && canPlay)
     {
         int toPlay = Random.Range(0, setArray[info.hitSet].lastCollisionSound);
         CreateAudioEvent(setArray[info.hitSet].collisionSounds[toPlay], info);
     }
 }
コード例 #2
0
        //Applies hit effects like sparks. Called from either ApplyDecal or ApplyDent
        public void ApplyHitEffect(HitEffectArray info)
        {
            //The info array has hit.point, hitRotation, hit.transform, hit.normal, hitSet
            if (setArray[info.hitSet].hitParticles[0] != null)
            {
                Vector3    tempVector  = info.hitPoint;
                Quaternion tempQuat1   = info.hitRotation;
                Transform  tempTrans2  = info.hitTransform;
                Vector3    tempVector3 = info.hitNormal;
                int        tempInt4    = info.hitSet;

                int        toApply = Random.Range(0, setArray[tempInt4].lastHitParticle);
                GameObject clone   = Instantiate(setArray[tempInt4].hitParticles[toApply], tempVector, tempQuat1) as GameObject;
                clone.transform.localPosition = clone.transform.localPosition + .01f * tempVector3;
                clone.transform.LookAt(thePlayer.transform.position);
            }
        }
コード例 #3
0
        //Called by BulletSound and CollisionSound; actually does the legwork of creating an audio event and playing the correct sound
        public void CreateAudioEvent(AudioClip clipToPlay, HitEffectArray info)
        {
            audioEvent = new GameObject("Audio Event");
            Transform t = info.hitTransform;

            audioEvent.transform.position = t.position;
            audioEvent.AddComponent <AudioSource>();

            AudioSource source = audioEvent.GetComponent <AudioSource>();

            //source.rolloffMode = AudioRolloffMode.Linear;
            source.clip = clipToPlay;
            source.Play();

            audioEvent.AddComponent <TimedObjectDestructorDB>();
            audioEvent.GetComponent <TimedObjectDestructorDB>().timeOut = clipToPlay.length + .5f;
            canPlay       = false;
            lastSoundTime = Time.time;
        }
コード例 #4
0
ファイル: HitBox.cs プロジェクト: Elnya/FPS-Constructor-CS
 void OnCollisionEnter(Collision c)
 {
     if (isActive)
     {
         Object[] sendArray = new Object[2];
         sendArray[0] = damage as object as Object;
         sendArray[1] = true as object as Object;
         c.collider.SendMessageUpwards("ApplyDamage", sendArray, SendMessageOptions.DontRequireReceiver);
         if (c.gameObject.GetComponent <UseEffects>())
         {
             int layer1    = 1 << PlayerWeapons.playerLayer;
             int layer2    = 1 << 2;
             int layerMask = layer1 | layer2;
             layerMask = ~layerMask;
             RaycastHit hit;
             if (Physics.Raycast(GunScript.gameObject.transform.position, GunScript.gameObject.transform.forward, out hit, Mathf.Infinity, layerMask))
             {
                 //The effectsManager needs five bits of information
                 Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
                 int        hitSet      = c.gameObject.GetComponent <UseEffects>().setIndex;
                 // FIXME_VAR_TYPE hitInfo = new Array(hit.point, hitRotation, c.transform, hit.normal, hitSet);
                 // Changed
                 HitEffectArray hitInfo = new HitEffectArray();
                 hitInfo.hitPoint     = hit.point;
                 hitInfo.hitRotation  = hitRotation;
                 hitInfo.hitTransform = hit.transform;
                 hitInfo.hitNormal    = hit.normal;
                 hitInfo.hitSet       = hitSet;
                 effectsManager.SendMessage("ApplyDent", hitInfo, SendMessageOptions.DontRequireReceiver);
             }
         }
         if (c.collider.GetComponent <Rigidbody>() != null)
         {
             c.collider.GetComponent <Rigidbody>().AddForce(c.relativeVelocity * force);
         }
         GunScript.hitBox = false;
         isActive         = false;
         GetComponent <AudioSource>().loop = false;
     }
 }
コード例 #5
0
        //Some weapons may apply 'dents' instead of 'decals' - for example, hitting a sheet of metal with a pipe would not make a round bullet hole appear.
        //This functions identically to ApplyDecal, only it is used in cases where dents are applied instead of the default decal.
        public void ApplyDent(HitEffectArray info)
        {
            //The info array has hit.point, hitRotation, hit.transform, hit.normal, hitSet

            if (setArray[0] != null)
            {
                if (setArray[info.hitSet].dentDecals[0] != null)
                {
                    Vector3    tempVector  = info.hitPoint;
                    Quaternion tempQuat1   = info.hitRotation;
                    Transform  tempTrans2  = info.hitTransform;
                    Vector3    tempVector3 = info.hitNormal;
                    int        tempInt4    = info.hitSet;

                    int        toApply = Random.Range(0, setArray[tempInt4].lastBulletDecal);
                    GameObject clone   = Instantiate(setArray[tempInt4].bulletDecals[toApply], tempVector, tempQuat1) as GameObject;
                    clone.transform.localPosition += .05f * tempVector3;
                    clone.transform.parent         = tempTrans2;
                    if (currentDecal >= maxDecals)
                    {
                        currentDecal = 0;
                    }
                    if (decalArray[currentDecal] != null)
                    {
                        Destroy(decalArray[currentDecal]);
                    }
                    decalArray[currentDecal] = clone;
                    currentDecal++;
                }
                ApplyHitEffect(info);
                CollisionSound(info);
            }
            else
            {
                Debug.LogWarning("EffectsManager: You have at least one object with the UseDecals script attached, but no decal sets. Please create a decal set");
            }
        }
コード例 #6
0
        public void Fire(int penetration, float damage, float force, GameObject tracer, Vector3 direction, Vector3 firePosition)
        {
            //must pass in penetation level, damage, force, tracer object (optional), direction to fire in, and position top fire from.

            bool penetrate = true;
            int  pVal      = penetration;
            int  layer2    = 1 << 2;
            int  layerMask = layer2;

            layerMask = ~layerMask;
            RaycastHit[] hits;
            hits             = Physics.RaycastAll(firePosition, direction, 100, layerMask);
            shotCountTracer += 1;
            if (tracer != null && traceEvery <= shotCountTracer)
            {
                shotCountTracer = 0;
                if (hits.Length > 0)
                {
                    tracer.transform.LookAt(hits[0].point);
                }
                else
                {
                    tracer.transform.LookAt((transform.position + 90 * direction));
                }
                tracer.GetComponent <ParticleEmitter>().Emit();
                tracer.GetComponent <ParticleEmitter>().Simulate(0.02f);
            }
            System.Array.Sort(hits, Comparison);
            //	 Did we hit anything?
            for (int i = 0; i < hits.Length; i++)
            {
                RaycastHit        hit = hits[i];
                BulletPenetration BP  = hit.transform.GetComponent <BulletPenetration>();
                if (penetrate)
                {
                    if (BP == null)
                    {
                        penetrate = false;
                    }
                    else
                    {
                        if (pVal < BP.penetrateValue)
                        {
                            penetrate = false;
                        }
                        else
                        {
                            pVal -= BP.penetrateValue;
                        }
                    }
                    //DAmage Array
                    // TODO: VERY AWKWARD, needed to send pair or two parameter.
                    Object[] sendArray = new Object[2];
                    sendArray[0] = (Object)(object)damage;
                    sendArray[1] = (Object)(object)false;
                    // Send a damage message to the hit object
                    hit.collider.SendMessageUpwards("ApplyDamage", sendArray, SendMessageOptions.DontRequireReceiver);
                    hit.collider.SendMessageUpwards("Direction", transform, SendMessageOptions.DontRequireReceiver);
                    //And send a message to the decal manager, if the target uses decals
                    if (hit.transform.gameObject.GetComponent <UseEffects>())
                    {
                        //The effectsManager needs five bits of information
                        Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
                        int        hitSet      = hit.transform.gameObject.GetComponent <UseEffects>().setIndex;
                        //Array hitInfo = new Array(hit.point, hitRotation, hit.transform, hit.normal, hitSet);
                        // Changed
                        HitEffectArray hitInfo = new HitEffectArray();
                        hitInfo.hitPoint     = hit.point;
                        hitInfo.hitRotation  = hitRotation;
                        hitInfo.hitTransform = hit.transform;
                        hitInfo.hitNormal    = hit.normal;
                        hitInfo.hitSet       = hitSet;
                        effectsManager.SendMessage("ApplyDecal", hitInfo, SendMessageOptions.DontRequireReceiver);
                    }
                    // Apply a force to the rigidbody we hit
                    if (hit.rigidbody)
                    {
                        hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
                    }
                }
            }
            BroadcastMessage("MuzzleFlash", true, SendMessageOptions.DontRequireReceiver);
            GameObject audioObj = new GameObject("GunShot");

            audioObj.transform.position = transform.position;
            audioObj.transform.parent   = transform;
            audioObj.AddComponent <TimedObjectDestructorDB>().timeOut = GetComponent <AudioSource>().clip.length + 0.1f;
            AudioSource aO = audioObj.AddComponent <AudioSource>();

            aO.clip   = GetComponent <AudioSource>().clip;
            aO.volume = GetComponent <AudioSource>().volume;
            aO.pitch  = GetComponent <AudioSource>().pitch;
            aO.Play();
            aO.loop        = false;
            aO.rolloffMode = AudioRolloffMode.Linear;
        }