99 lines
1.9 KiB
C#
99 lines
1.9 KiB
C#
using UnityEngine;
|
|
using UnityStandardAssets.Utility;
|
|
|
|
public class WaterSplashAnim : MonoBehaviour
|
|
{
|
|
public Texture2D[] splashesTextures;
|
|
|
|
public Renderer[] planesToRender;
|
|
|
|
private int currentFrame;
|
|
|
|
[SerializeField]
|
|
private bool loop = true;
|
|
|
|
[SerializeField]
|
|
private bool directionOnCamera = true;
|
|
|
|
[SerializeField]
|
|
private bool DestroyByTime = true;
|
|
|
|
[SerializeField]
|
|
private bool DestroyByDone = true;
|
|
|
|
private bool isAnimDone;
|
|
|
|
public int frameStep = 2;
|
|
|
|
private AudioSource m_AudioSource;
|
|
|
|
[SerializeField]
|
|
private AudioClip[] m_soundsSplash;
|
|
|
|
private void Start()
|
|
{
|
|
if (!DestroyByTime)
|
|
{
|
|
Object.Destroy(GetComponent<TimedObjectDestructor>());
|
|
}
|
|
m_AudioSource = GetComponent<AudioSource>();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (directionOnCamera && Camera.main != null)
|
|
{
|
|
Vector3 worldPosition = new Vector3(Camera.main.transform.position.x, base.transform.position.y, Camera.main.transform.position.z);
|
|
base.transform.LookAt(worldPosition);
|
|
}
|
|
playingAnim();
|
|
}
|
|
|
|
private void playingAnim()
|
|
{
|
|
if (isAnimDone)
|
|
{
|
|
return;
|
|
}
|
|
playSound();
|
|
for (int i = 0; i < planesToRender.Length; i++)
|
|
{
|
|
planesToRender[i].material.mainTexture = splashesTextures[currentFrame];
|
|
}
|
|
if (currentFrame >= splashesTextures.Length - 2)
|
|
{
|
|
currentFrame = 0;
|
|
if (!loop)
|
|
{
|
|
isAnimDone = true;
|
|
if (DestroyByDone)
|
|
{
|
|
Object.Destroy(base.gameObject);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
currentFrame += frameStep;
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
isAnimDone = false;
|
|
currentFrame = 0;
|
|
}
|
|
|
|
private void playSound()
|
|
{
|
|
if (!m_AudioSource.isPlaying && m_soundsSplash.Length != 0)
|
|
{
|
|
int num = Random.Range(1, m_soundsSplash.Length);
|
|
m_AudioSource.clip = m_soundsSplash[num];
|
|
m_AudioSource.PlayOneShot(m_AudioSource.clip, 0.3f);
|
|
m_soundsSplash[num] = m_soundsSplash[0];
|
|
m_soundsSplash[0] = m_AudioSource.clip;
|
|
}
|
|
}
|
|
}
|