Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

New developer right here, seeking to do some raycasting and controlling audio positioning in 3D area based mostly on the raycasts interactions with different objects.
I’ve bought the raycast ‘casting’ and in a position to report again the place it collides different objects and managed to get audio to play again at that raycast level utilizing AudioSource.PlayClipAtPoint()

Nonetheless, PlayClipAtPoint would not permit me to alter the audio 3d attenuation settings as a one shot audio object is generated after which eliminated instantly and I am unable to discover any parameters to manage this new object other than a quantity 0-1 float worth.

I got here throughout this put up by Aldonaletto:

operate PlayClipAt(clip: AudioClip, pos: Vector3): AudioSource; {
   var tempGO = GameObject("TempAudio"); // create the temp object
   tempGO.rework.place = pos; // set its place
   var aSource = tempGO.AddComponent(AudioSource); // add an audio supply
   aSource.clip = clip; // outline the clip
   // set different aSource properties right here, if desired
   aSource.Play(); // begin the sound
   Destroy(tempGO, clip.size); // destroy object after clip length
   return aSource; // return the AudioSource reference
 }

However can not seem to get the native operate to work in Unity because it complains about not utilizing C# model 7 or above. If I improve the C# model in visible studio I get compiler errors on Unity’s aspect.

Little bit caught, would recognize some recommendation! Some code under, simply unsure what to place into the results of the if assertion to get this to work.

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class raycasting : MonoBehaviour
{
    public float raycastlength = 3;
    public AudioClip playthis;
    public float ER_Volume = 1F;

    // Use this for initialization
    void Begin()
    {
        //Debug.Log("I am a sphere, yo!");
    }

    // Replace is known as as soon as per body
    void Replace()
    {
        RaycastHit hit;
        Ray forwardray = new Ray(rework.place, Vector3.ahead);

        //draw the raycast in scene view
        Debug.DrawRay(rework.place, Vector3.ahead * raycastlength, Colour.white);

        if (Enter.GetMouseButtonDown(0))
        {
            //Debug.Log("We pressed the fireplace button!");
            if (Physics.Raycast(forwardray, out hit, raycastlength))
            {
                if (hit.collider.tag == "evil")
                {
                    Debug.Log("Raycast Hit!");
                    Debug.Log("Distance to object:" + hit.distance);
                    //Debug.Log("Object hit level:" + hit.level);

                    //play a sound utilizing playclipatpoint, however this does not permit us to alter attenuation settings
                    AudioSource.PlayClipAtPoint(playthis, hit.level, ER_Volume);
                }
            }
        }
    }
}

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *