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. Dismiss Notice

Error in code? SOLVED

Discussion in 'Scripting' started by corriedotdev, Mar 17, 2013.

  1. corriedotdev

    corriedotdev

    Joined:
    Sep 1, 2012
    Posts:
    21
    #pragma strict

    var papers : int = 0;
    var papersToWin : int = 8;
    var distanceToPaper : float = 2.5;
    public var paperpickup : AudioClip;
    public var sound : audioclip;

    function Start()
    {
    Screen.lockCursor = true;
    }

    function Update()
    {
    if ( Input.GetMouseButtonUp(0) )
    {
    var ray = Camera.main.ScreenPointToRay( Input.mousePosition );
    var hit : RaycastHit;
    if ( Physics.Raycast( ray, hit, distanceToPaper ) )
    {
    if ( hit.collider.gameObject.name == "Paper" )
    {
    papers += 1;
    audio.PlayOneShot(paperpickup);
    Debug.Log( "A part was picked up. Total parts = " + papers );
    Destroy( hit.collider.gameObject );
    }
    }
    }
    }
    function scary()
    {
    if (papers === 4);
    {
    audio.playoneshot(scary);
    }
    }


    function OnGUI()
    {
    if ( papers < papersToWin )
    {
    GUI.Box( Rect( (Screen.width/2)-100, 10, 200, 35 ), "Parts collected " + papers );
    }
    else
    {
    GUI.Box( Rect( (Screen.width/2)-100, 10, 200, 35 ), "Return to ship to escape" );
    }
    }


    Areas underlined is where the problem is occuring. Probs a obvious mistake but i tried :/

    cheers guys :p
     
    Last edited: Mar 17, 2013
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    [ code ] [/ code] tags on pasted code...

    and you've missed the capitalisation on the audioclip (ie AudioClip not audioclip)
    and equals (ie is this the same as that?) is ==
     
  3. corriedotdev

    corriedotdev

    Joined:
    Sep 1, 2012
    Posts:
    21
    I know but cant underline code in the code boxes. Thanks for your input but that is not the problem, i changed the loads
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    When you use the code tags, there are line numbers and you can refer to them. It is a lot easier to read formatted code than just a text without indentation.
     
    corriedotdev likes this.
  5. corriedotdev

    corriedotdev

    Joined:
    Sep 1, 2012
    Posts:
    21
    I would just like to apologise for the awful post. Code isnt formatted and i didnt go into detail what the issue was. This was one of the first scripts i wrote in c#. Im much more advanced now and can understand its annoying when posts like these are made. Sorry and thanks!
     
    Dantus likes this.