Esempio n. 1
0
        void TriggerSound(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            if (_random == null)
            {
                _random = new vFisherYatesRandom();
            }
            isTrigger = true;
            GameObject audioObject = null;

            if (audioSource != null)
            {
                audioObject = Instantiate(audioSource.gameObject, animator.transform.position, Quaternion.identity) as GameObject;
            }
            else
            {
                audioObject = new GameObject("audioObject");
                audioObject.transform.position = animator.transform.position;
            }
            if (audioObject != null)
            {
                var source = audioObject.gameObject.GetComponent <AudioSource>();
                var clip   = sounds[_random.Next(sounds.Count)];
                source.PlayOneShot(clip);
            }
        }
        public override void Init()
        {
            base.Init();

            if (randomWaypoint == null)
            {
                randomWaypoint = new vFisherYatesRandom();
            }
            if (randomPatrolPoint == null)
            {
                randomPatrolPoint = new vFisherYatesRandom();
            }

            currentWaypoint    = -1;
            currentPatrolPoint = -1;
            fwd         = transform.forward;
            destination = transform.position;
            agent       = GetComponent <UnityEngine.AI.NavMeshAgent>();

            agentPath    = new UnityEngine.AI.NavMeshPath();
            sphereSensor = GetComponentInChildren <v_AISphereSensor>();
            if (sphereSensor)
            {
                sphereSensor.SetColliderRadius(maxDetectDistance);
                sphereSensor.tagsToDetect    = tagsToDetect;
                sphereSensor.passiveToDamage = passiveToDamage;
            }
            meleeManager = GetComponent <vMeleeManager>();
            canAttack    = true;
            attackCount  = 0;
            sideMovement = GetRandonSide();
            destination  = transform.position;

            _rigidbody             = GetComponent <Rigidbody>();
            _rigidbody.useGravity  = true;
            _rigidbody.constraints = RigidbodyConstraints.None | RigidbodyConstraints.FreezeRotation;
            agent.updatePosition   = false;
            agent.updateRotation   = false;
            agent.enabled          = false;
            _capsuleCollider       = GetComponent <CapsuleCollider>();

            // avoid collision detection with inside colliders
            Collider[] AllColliders = this.GetComponentsInChildren <Collider>();
            Collider   thisCollider = GetComponent <Collider>();

            for (int i = 0; i < AllColliders.Length; i++)
            {
                Physics.IgnoreCollision(thisCollider, AllColliders[i]);
            }

            healthSlider  = GetComponentInChildren <v_SpriteHealth>();
            head          = animator.GetBoneTransform(HumanBodyBones.Head);
            oldPosition   = transform.position;
            currentHealth = maxHealth;
            startPosition = transform.position;
        }
Esempio n. 3
0
    public void PlayRandomClip(FootStepObject footStepObject)
    {
        // if there are no clips to play return.
        if (audioClips == null || audioClips.Count == 0)
        {
            return;
        }

        // initialize variable if not already started
        if (randomSource == null)
        {
            randomSource = new vFisherYatesRandom();
        }

        // find a random clip and play it.
        GameObject audioObject = null;

        if (audioSource != null)
        {
            audioObject = Instantiate(audioSource.gameObject, footStepObject.sender.position, Quaternion.identity) as GameObject;
        }
        else
        {
            audioObject = new GameObject("audioObject");
            audioObject.transform.position = footStepObject.sender.position;
        }

        var source = audioObject.AddComponent <vAudioSurfaceControl>();

        if (audioMixerGroup != null)
        {
            source.outputAudioMixerGroup = audioMixerGroup;
        }
        int index = randomSource.Next(audioClips.Count);

        if (particleObject && footStepObject.ground && stepLayer.ContainsLayer(footStepObject.ground.gameObject.layer))
        {
            Instantiate(particleObject, footStepObject.sender.position, footStepObject.sender.rotation);
        }
        if (useStepMark)
        {
            StepMark(footStepObject);
        }

        source.PlayOneShot(audioClips[index]);
    }
Esempio n. 4
0
    public void PlayRandomClip(FootStepObject footStepObject)
    {
        // If there are no clips to play return.
        if (audioClips == null || audioClips.Count == 0)
        {
            return;
        }

        // initialize variable if not already started
        if (randomSource == null)
        {
            randomSource = new vFisherYatesRandom();
        }
        // Find a random clip and play it.
        GameObject audioObject = null;

        if (audioSource != null)
        {
            audioObject = Instantiate(audioSource.gameObject, footStepObject.sender.position, Quaternion.identity) as GameObject;
        }
        else
        {
            audioObject = new GameObject("audioObject");
            audioObject.transform.position = footStepObject.sender.position;
        }

        var source = audioObject.AddComponent <vAudioSurfaceControl>();

        if (audioMixerGroup != null)
        {
            source.outputAudioMixerGroup = audioMixerGroup;
        }
        int index = randomSource.Next(audioClips.Count);

        if (particleObject)
        {
            var particle = Instantiate(particleObject, footStepObject.sender.position, footStepObject.sender.rotation) as GameObject;

            particle.SendMessage("StepMark", footStepObject, SendMessageOptions.DontRequireReceiver);
        }
        source.PlayOneShot(audioClips[index]);
    }