Created
January 14, 2018 07:43
-
-
Save soundtweaker/1c92a8f178e856b1330b5b9db91176f1 to your computer and use it in GitHub Desktop.
Occlusion/Obstruction Script for Unity and Wwise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
public class DrawRay : MonoBehaviour { | |
public Transform target; | |
public GameObject listener; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
RaycastHit HitInfo; | |
float playerDistance; | |
Vector3 raycastDir = target.position - transform.position; | |
playerDistance = Vector3.Distance(target.position, transform.position); | |
Physics.Raycast(transform.position, raycastDir, out HitInfo, playerDistance); | |
if (HitInfo.collider == null) | |
{ | |
AkSoundEngine.SetObjectObstructionAndOcclusion(this.gameObject, listener, 0.0f, 0.0f); | |
Debug.DrawRay(transform.position, raycastDir, Color.blue); | |
} | |
else if (HitInfo.collider.tag == "Wall") | |
{ | |
AkSoundEngine.SetObjectObstructionAndOcclusion(this.gameObject, listener, 0.0f, 100.0f); | |
Debug.DrawRay(transform.position, raycastDir, Color.red); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment