Post by Legion on Jan 30, 2017 5:13:03 GMT
RustleFx.cs
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
using System.Collections.Generic;
public class RustleFx : MonoBehaviour
{
[Tooltip("Values between 0 and 1 || 0 = No sound, 1 = Max Volume")]
public float VolumeFx = 1f;
[Tooltip("Values between -3 and 3 || -3 = Min Pitch, 3 = Max Pitch")]
public float PitchFx = 1f;
[Tooltip("Values between 0 and 1 || 0 = 2D, 1 = 3D")]
public float SpatialBlend = 1f;
public AudioClip[] SoundsToPlay;
private AudioSource audioSource;
private AudioClip PlayClip;
public UnityEvent OnPlayerEnter, OnPlayerStay;
void Start()
{
audioSource = transform.gameObject.AddComponent<AudioSource>();
audioSource.spatialBlend = SpatialBlend;
audioSource.volume = VolumeFx;
audioSource.pitch = PitchFx;
audioSource.dopplerLevel = 0.0f;
audioSource.maxDistance = 10.0f;
audioSource.rolloffMode = AudioRolloffMode.Logarithmic;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
int index = Random.Range(0, SoundsToPlay.Length);
PlayClip = SoundsToPlay[index];
audioSource.clip = PlayClip;
audioSource.Play();
OnPlayerEnter.Invoke();
}
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
OnPlayerStay.Invoke();
}
}
}
A script to play a random sound from a list when the character enters a bush (or whatever you can think of).
It contains 2 events for OnTriggerEnter and OnTriggerStay, to expand its use; for example, we use OnTriggerEnter to activate falling leaf particles and OnTriggerStay to hide the character from the AI. In some kind of bushes it also used to activate insect particles over time and have the character play the animation of shooing them with her hands.
Instructions for use:
- Add a collider as a trigger to the prefab you want.
- Add the script below and place the sounds you want to play.
- (Optional) Change the default values for volume, pitch, etc.
- (Optional) Place the prefab in the "Triggers" layer.
Old thread.
We've been testing different effects combinations for light sabers and we are quite satisfied with this one, so we would like to share it in case someone wants to use it.
Download
Content:
- 3 materials.
- 2 textures.
- 1 shader.
- 1 prefab.
Next to do:Initial flash, smoke and impact decals.
Download
Content:
- 3 materials.
- 2 textures.
- 1 shader.
- 1 prefab.
Next to do: