Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity script error

Discussion in 'Scripting' started by halojman, Mar 17, 2016.

  1. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27
    I'm working on an Audio Script (I got it off the asset store, I'm just fixing the bugs) Anyway, I managed to fix most of the bugs, but I can't fix this one:

    Assets/Inventory/Scripts/Other/InvAudio.js(49,29): BCE0051: Operator '<' cannot be used with a left hand side of type 'function(System.Type): UnityEngine.Component' and a right hand side of type 'System.Type'.

    My script is:

    #pragmastrict

    //Thesound clips
    var openSound : AudioClip;
    var closeSound : AudioClip;
    var equipSound : AudioClip;
    var pickUpSound : AudioClip;
    var dropItemSound : AudioClip;

    @script RequireComponent(AudioSource)
    @script AddComponentMenu ("Inventory/Other/InvAudio")

    function Awake ()
    {
    //ThisiswherewecheckifthescriptisattachedtotheInventory.
    if (transform.name != "Inventory")
    {
    Debug.LogError("AnInvAudioscriptisplacedon" + transform.name + ".Itshouldonlybeattachedtoan'Inventory'object");
    }

    //Thisiswhereweassignthedefaultsoundsifnothingelsehasbeenputin.
    if (openSound == null)
    {
    openSound = Resources.Load("Sounds/InvOpenSound", AudioClip);
    }
    if (closeSound == null)
    {
    closeSound = Resources.Load("Sounds/InvCloseSound", AudioClip);
    }
    if (equipSound == null)
    {
    equipSound = Resources.Load("Sounds/InvEquipSound", AudioClip);
    }
    if (pickUpSound == null)
    {
    pickUpSound = Resources.Load("Sounds/InvPickUpSound", AudioClip);
    }
    if (dropItemSound == null)
    {
    dropItemSound = Resources.Load("Sounds/InvDropItemSound", AudioClip);
    }
    }

    //Thisiswhereweplaytheopenandclosesounds.
    function ChangedState (open : boolean)
    {
    if (open)
    {
    GetComponent<AudioSource>(
    GetComponent.<AudioSource>().pitch ) ;Random.Range(0.85, 1.1);
    GetComponent.<AudioSource>().Play();
    }
    else
    {
    GetComponent.<AudioSource>().clip = closeSound;
    GetComponent.<AudioSource>().pitch = Random.Range(0.85, 1.1);
    GetComponent.<AudioSource>().Play();
    }
    }

    //TherestofthefunctionscaneasilybecalledtoplaydifferentsoundsusingSendMessage("Play<NameOfSound>",SendMessageOptions.DontRequireReceiver);

    function PlayEquipSound ()
    {
    GetComponent.<AudioSource>().clip = equipSound;
    GetComponent.<AudioSource>().pitch = Random.Range(0.85, 1.1);
    GetComponent.<AudioSource>().Play();
    }

    function PlayPickUpSound ()
    {
    GetComponent.<AudioSource>().clip = pickUpSound;
    GetComponent.<AudioSource>().pitch = Random.Range(0.85, 1.1);
    GetComponent.<AudioSource>().Play();
    }

    function PlayDropItemSound ()
    {
    GetComponent.<AudioSource>().clip = dropItemSound;
    GetComponent.<AudioSource>().pitch = Random.Range(0.85, 1.1);
    GetComponent.<AudioSource>().Play();
    }
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Please use code tags. That makes reading so much easier.

    The errors are in this piece:
    Code (JavaScript):
    1. if (open)
    2. {
    3. GetComponent<AudioSource>( // something missing here
    4. GetComponent.<AudioSource>().pitch ) ;Random.Range(0.85, 1.1); // another error here. should be an assignment
    5. GetComponent.<AudioSource>().Play();
    6. }
     
    halojman likes this.
  3. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27
    Thanks I fixed the first line of code, But on the second one, with //another error here. should be an assignment,

    I get these errors:


    Assets/Inventory/Scripts/Other/InvAudio.js(50,17): BCE0044: expecting ), found 'GetComponent'.

    and

    Assets/Inventory/Scripts/Other/InvAudio.js(50,52): BCE0043: Unexpected token: ).
     
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    This
    Code (JavaScript):
    1. GetComponent.<AudioSource>().pitch ) ;Random.Range(0.85, 1.1);
    should be this:
    Code (JavaScript):
    1. GetComponent.<AudioSource>().pitch = Random.Range(0.85, 1.1);
     
    halojman likes this.
  5. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27
    I did that, But I got the same errors, Plus this one:


    Assets/Inventory/Scripts/Other/InvAudio.js(50,55): UCE0001: ';' expected. Insert a semicolon at the end.
     
  6. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27

    Okay, I fixed the bugs, and got it back to

    Assets/Inventory/Scripts/Other/InvAudio.js(49,46): BCE0019: 'openSound' is not a member of 'UnityEngine.AudioSource'.
     
  7. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27
    Nevermind, all the errors are fixed now.