void OnFootstep() { if (!audioSource.enabled) { return; } AudioClip sound = null; switch (footType) { case FootType.Player: sound = MaterialImpactManager.GetPlayerFootstepSound(physicMaterial); break; case FootType.Mech: sound = MaterialImpactManager.GetMechFootstepSound(physicMaterial); break; case FootType.Spider: sound = MaterialImpactManager.GetSpiderFootstepSound(physicMaterial); break; } audioSource.pitch = Random.Range(0.98f, 1.02f); audioSource.PlayOneShot(sound, Random.Range(0.8f, 1.2f)); }
void Update() { if (firing) { if (Time.time > lastFireTime + 1 / frequency) { // Spawn visual bullet Quaternion coneRandomRotation = Quaternion.Euler(Random.Range(-coneAngle, coneAngle), Random.Range(-coneAngle, coneAngle), 0); GameObject go = Spawner.Spawn(bulletPrefab, spawnPoint.position, spawnPoint.rotation * coneRandomRotation) as GameObject; SimpleBullet bullet = go.GetComponent <SimpleBullet> (); lastFireTime = Time.time; // Find the object hit by the raycast RaycastHit hitInfo = raycast.GetHitInfo(); if (hitInfo.transform) { // Get the health component of the target if any Health targetHealth = hitInfo.transform.GetComponent <Health> (); if (targetHealth) { // Apply damage targetHealth.OnDamage(damagePerSecond / frequency, -spawnPoint.forward); } // Get the rigidbody if any if (hitInfo.rigidbody) { // Apply force to the target object at the position of the hit point Vector3 force = transform.forward * (forcePerSecond / frequency); hitInfo.rigidbody.AddForceAtPosition(force, hitInfo.point, ForceMode.Impulse); } // Ricochet sound AudioClip sound = MaterialImpactManager.GetBulletHitSound(hitInfo.collider.sharedMaterial); AudioSource.PlayClipAtPoint(sound, hitInfo.point, hitSoundVolume); bullet.dist = hitInfo.distance; } else { bullet.dist = 1000; } } } }
void Awake() { _instance = this; }