CreateAudioSource() public static method

Creates and attaches a new audio source component to the given game object. The audio source will play the audio clip provided.
public static CreateAudioSource ( GameObject obj, AudioClip clip ) : AudioSource
obj GameObject The game object the audio source component is attached to.
clip UnityEngine.AudioClip The audio clip for the audio source component.
return UnityEngine.AudioSource
コード例 #1
0
 void Start()
 {
     // Setup audio
     buttonClick     = AudioHelper.CreateAudioSource(gameObject, buttonClickSound);
     countdownSource = AudioHelper.CreateAudioSource(gameObject, countdownSound);
     goSource        = AudioHelper.CreateAudioSource(gameObject, goSound);
 }
コード例 #2
0
 void Awake()
 {
     Instance        = this;
     buttonSource    = AudioHelper.CreateAudioSource(gameObject, buttonSound);
     countdownSource = AudioHelper.CreateAudioSource(gameObject, countdownSound);
     goSource        = AudioHelper.CreateAudioSource(gameObject, goSound);
 }
コード例 #3
0
 void Start()
 {
     // Create audio sources for sound playback.
     ballHitBlockSource = AudioHelper.CreateAudioSource(gameObject, ballHitBlock);
     ballHitTableSource = AudioHelper.CreateAudioSource(gameObject, ballHitTable);
     ballRollSource     = AudioHelper.CreateAudioSource(gameObject, ballRoll);
 }
コード例 #4
0
    void Start()
    {
        buttonSource = AudioHelper.CreateAudioSource(gameObject, buttonSound);

        var colliderPos = new Vector3(0.5f, 1f, 80f);

        colliderPos = Camera.main.ViewportToWorldPoint(colliderPos);
    }
コード例 #5
0
    void Awake()
    {
        // Register this script as the singleton instance.
        Instance = this;

        // Create audio sources for sound playback.
        hiveGrowSource = AudioHelper.CreateAudioSource(gameObject, hiveGrowSound);
    }
コード例 #6
0
 void Start()
 {
     currentVerticalSpeed = 0;
     rb = GetComponent <Rigidbody>();
     rb.centerOfMass = rb.position - new Vector3(0, 0, 1);
     carSource       = AudioHelper.CreateAudioSource(gameObject, carSound);
     crashSource     = AudioHelper.CreateAudioSource(gameObject, crashSound);
 }
コード例 #7
0
    void Start()
    {
        myRigidbody = GetComponent <Rigidbody>();

        slowMoveSource = AudioHelper.CreateAudioSource(gameObject, slowMoveAudio);
        fastMoveSource = AudioHelper.CreateAudioSource(gameObject, fastMoveAudio);
        pickupSource   = AudioHelper.CreateAudioSource(gameObject, pickupAudio);
    }
コード例 #8
0
 void OnEnable()
 {
     // Check if we have a audio source, if not create a new one.
     if (source == null)
     {
         source = AudioHelper.CreateAudioSource(gameObject, sound);
     }
     source.Play();
 }
コード例 #9
0
    // Use this for initialization
    void Start()
    {
        targetHitSource = AudioHelper.CreateAudioSource(gameObject, targetHitSound);

        gravityController = GetComponent <GravityController>();
        rigidBody         = GetComponent <Rigidbody>();

        activated = false;
    }
コード例 #10
0
    void Awake()
    {
        // Keep references to the bee's flight path and colliders.
        flightPath = GetComponentInChildren <FlightPath>();
        colliders  = GetComponentsInChildren <Collider>();

        // Create audio sources for sound playback.
        stunnedSource = AudioHelper.CreateAudioSource(gameObject, stunnedSound);
    }
コード例 #11
0
    // Use this for initialization
    void Start()
    {
        launchSource = AudioHelper.CreateAudioSource(gameObject, launchSound);

        rigidBodyComp     = GetComponent <Rigidbody>();
        gravityController = GetComponent <GravityController>();

        mouseDown = false;
        launched  = false;
        ClearExpectedPath();
    }
コード例 #12
0
    void Start()
    {
        // Setup audio for different diamond amounts
        diamondRevealSources = new List <AudioSource>();
        for (int i = 0; i < diamondRevealSounds.Length; ++i)
        {
            diamondRevealSources.Add(AudioHelper.CreateAudioSource(gameObject, diamondRevealSounds[i]));
        }

        // Setup other audio
        digSource     = AudioHelper.CreateAudioSource(gameObject, digSound);
        explodeSource = AudioHelper.CreateAudioSource(gameObject, explodeSound);
    }
コード例 #13
0
    /// <summary>
    /// Sets the stickyness.
    /// </summary>
    /// <param name="index">Level of stickiness.</param>
    public void SetStickyness(int index)
    {
        index = Mathf.Clamp(index, 0, stickyStages.Length - 1);

        // Set our stickiness and update speed/collider for the new stage
        stickyness        = stickyStages[index].stickiness;
        multiplier        = stickyStages[index].speedMultiplier;
        myCollider.radius = baseRadius + stickyStages[index].radiusIncrease;
        collisionOffset   = stickyStages[index].pickupDistanceScale;

        // Change audio for new stage
        pickupSource = AudioHelper.CreateAudioSource(gameObject, stickyStages[index].collectSound);
        ChangeMovementSound();
    }
コード例 #14
0
    // Use this for initialization
    void Start()
    {
        fileManagement = GameObject.FindGameObjectWithTag("fileManager").GetComponent <FileManagement>();

        carSource         = AudioHelper.CreateAudioSource(gameObject, carSound);
        outputToFile      = false;
        interval          = 0;
        threeSecondWait   = 0;
        startTimer        = false;
        responseTimer     = 0;
        waitForResponse   = false;
        startWaitingTimer = 0;
        trigger           = false;
        intervalSetToPlay = 0;
        filePath          = fileManagement.getFilePath();
    }
コード例 #15
0
    void Start()
    {
        // Compute the total spawn weight.
        foreach (var type in beeTypes)
        {
            totalSpawnWeight += type.spawnWeight;
        }

        // Create audio sources for sound playback.
        buzzSoundSource = AudioHelper.CreateAudioSource(gameObject, buzzSoundLoop);

        // Kick off the buzz sound loop, but set volume to zero initially.
        buzzVolumeMax          = buzzSoundSource.volume;
        buzzSoundSource.volume = buzzVolumeCurrent;
        buzzSoundSource.Play();
    }
コード例 #16
0
    void Start()
    {
        exhaustSource = AudioHelper.CreateAudioSource(gameObject, exhaustAudio);
        windSource    = AudioHelper.CreateAudioSource(gameObject, windAudio);

        myRigidbody   = GetComponent <Rigidbody>();
        startPosition = myRigidbody.position;

        // Set center of mass value directly in physics engine.
        // Unfortunately, Unity does not have a center of pressure built-in.
        bodyLength = GetComponent <CapsuleCollider>().height;
        myRigidbody.centerOfMass = new Vector3(0f, centerOfMass * bodyLength, 0f);

        // Set rocket to initial state
        Reset();
    }
コード例 #17
0
    /// <summary>
    /// Logic that runs when the object is initialized.
    /// </summary>
    void Start()
    {
        moving = false;

        myTransform = GetComponent <Transform>();
        myRigidbody = GetComponent <Rigidbody>();
        myCollider  = GetComponentInChildren <SphereCollider>();

        baseRadius = myCollider.radius;

        cameraOffset = cameraTransform.position - myTransform.position;

        SetStickyness(0);

        lowRollSource  = AudioHelper.CreateAudioSource(gameObject, lowRollSound);
        highRollSource = AudioHelper.CreateAudioSource(gameObject, highRollSound);
    }
コード例 #18
0
    // ------------------------------------------------------------------------------------------------------ //
    // --------------------------------------------- S T A R T ---------------------------------------------- //
    // ------------------------------------------------------------------------------------------------------ //
    void Start()
    {
        // pointsUI.text = "Points: 0";
        pointsUI.text        = "";
        points               = 0;
        numTimesCrashed      = 0; currentlyCrashing = 0;
        currentVerticalSpeed = 0;
        rb              = GetComponent <Rigidbody>();
        renderer        = GetComponent <Renderer>();
        rb.centerOfMass = rb.position - new Vector3(0, 0, 1);
        carSource       = AudioHelper.CreateAudioSource(gameObject, carSound);
        crashSource     = AudioHelper.CreateAudioSource(gameObject, crashSound);

        crashedX = 0; crashedY = 0; crashedZ = 0;
        passedX  = 0; passedY = 0; passedZ = 0;

        fileManagement = GameObject.FindGameObjectWithTag("fileManager").GetComponent <FileManagement>();
        filePath       = fileManagement.getFilePath();
    }
コード例 #19
0
    /// <summary>
    /// Logic that runs on object initialization.
    /// </summary>
    void Start()
    {
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible   = true;

        stageCompletedSource = AudioHelper.CreateAudioSource(gameObject, stageCompletedSound);

        currentLevel   = 0;
        finishedLevels = false;

        // Spawn the collectible objects
        SpawnProps();

        //update UI
        UIManager.Instance.UpdateHUD(timeSpent, GetRankForTime(timeSpent), Mathf.Max(0, levels[currentLevel].numToCollect - PropsCollected), levels[currentLevel].stage);

        UIManager.Instance.ShowCountdown(countdown);
        UIManager.Instance.ShowHUD(false);
        UIManager.Instance.ShowScreen("Tutorial");
    }
コード例 #20
0
    void Start()
    {
        droneMoveSource    = AudioHelper.CreateAudioSource(gameObject, droneMoveAudio);
        droneAlertSource   = AudioHelper.CreateAudioSource(gameObject, droneAlertAudio);
        dronePursuitSource = AudioHelper.CreateAudioSource(gameObject, dronePursuitAudio);

        // Keep references to commonly accessed components.
        agent      = GetComponent <NavMeshAgent>();
        perception = GetComponentInChildren <AIPerception>();

        // By default, the agent starts in the patrol state.
        perception.SetViewConeColor(normalColor);
        state = State.Patrol;

        // Track the agent's move speed.
        speed = agent.speed;

        // Store the list of waypoints from our patrol path.
        waypoints = new Transform[patrolPath.childCount];
        for (int i = 0; i < waypoints.Length; ++i)
        {
            waypoints[i] = patrolPath.GetChild(i);
        }

        // Loop through all the waypoints and pick the closest one. This is where
        // we should patrol toward first.
        float closestDistance = Vector3.Distance(transform.position, waypoints[0].position);

        for (int i = 1; i < waypoints.Length; ++i)
        {
            float distance = Vector3.Distance(transform.position, waypoints[i].position);
            if (distance < closestDistance)
            {
                closestDistance = distance;
                currentWaypoint = i;
            }
        }

        // Hide the alert icon by default.
        exclamationMark.SetActive(false);
    }
コード例 #21
0
 void Start()
 {
     // Create audio sources for sound playback.
     landSource = AudioHelper.CreateAudioSource(gameObject, landSound);
 }
コード例 #22
0
 void Start()
 {
     carSource = AudioHelper.CreateAudioSource(gameObject, carAudio);
 }
コード例 #23
0
 void Awake()
 {
     Instance    = this;
     musicSource = AudioHelper.CreateAudioSource(gameObject, musicSound);
 }
コード例 #24
0
 void Start()
 {
     switchSource = AudioHelper.CreateAudioSource(gameObject, switchAudio);
 }
コード例 #25
0
 // Use this for initialization
 void Start()
 {
     hornSource = AudioHelper.CreateAudioSource(gameObject, hornSound);
     played     = false;
 }
コード例 #26
0
 void Start()
 {
     // Create audio sources for sound playback.
     buttonClickSource = AudioHelper.CreateAudioSource(gameObject, buttonClick);
 }
コード例 #27
0
 void Start()
 {
     buttonClickSource = AudioHelper.CreateAudioSource(gameObject, buttonClickSound);
 }
コード例 #28
0
 // Use this for initialization
 void Start()
 {
     blackHoleSource = AudioHelper.CreateAudioSource(gameObject, blackHoleSound);
 }
コード例 #29
0
 void Awake()
 {
     source = AudioHelper.CreateAudioSource(gameObject, sound);
 }
コード例 #30
0
 void Start()
 {
     //Set up audio
     goalSource = AudioHelper.CreateAudioSource(gameObject, goalSound);
 }