gutterball-3/Gutterball 3/Assets/Scripts/TriggerSound.cs
SkunkStudios 0b195a0fc1 Custom Balls and Cosmic Alleys
Strike it big with amazing bowling action! Everything that made Gutterball 3D a hit is here - incredible 3D graphics, cool ball-rolling controls, hilarious characters - and more! Eight all-new alleys are waxed and ready for you to toss your choice of 85 unique bowling balls. As you play, earn points and cash and unlock alleys and balls. Even customize a ball with your own settings and images! Addictive bowling fun that will bowl you over!
2025-01-16 16:07:45 +07:00

77 lines
2.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Security;
using UnityEngine;
public class TriggerSound : MonoBehaviour
{
public string clipName;
public GameObject hitParticles;
public GameObject objectShake;
public float maxShake;
public bool isHitPins;
private float shakeTime;
private Vector2 shake;
private AudioSource audioSource;
private bool isBounce;
// Use this for initialization
void Start()
{
audioSource = GameObject.Find("SFXSource").GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
shake.x = Random.Range(-shakeTime, shakeTime);
shake.y = Random.Range(-shakeTime, shakeTime);
if (shakeTime > 0)
{
shakeTime -= Time.deltaTime;
}
if (shakeTime <= 0)
{
shakeTime = 0;
}
if (objectShake != null)
{
objectShake.transform.position = new Vector3(shake.x, shake.y, 0);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Ball" && !isBounce)
{
if (audioSource != null && GameManager.isSound && GameManager.type != GameManager.GameState.Menu)
{
audioSource.PlayOneShot(Resources.Load<AudioClip>("Sound/" + clipName));
}
isBounce = true;
}
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Ball") || other.CompareTag("Pin") && isHitPins)
{
if (hitParticles != null && GameManager.isParticle)
{
Vector3 splashPosition = new Vector3(other.transform.position.x, other.transform.position.y, transform.position.z);
Instantiate(hitParticles, splashPosition, Quaternion.Euler(0, 180, 0));
}
shakeTime = maxShake;
if (audioSource != null && GameManager.isSound && GameManager.type != GameManager.GameState.Menu)
{
audioSource.PlayOneShot(Resources.Load<AudioClip>("Sound/" + clipName));
}
}
}
public void Reset()
{
isBounce = false;
}
}