Cant pickup papers with script

I cant pickup papers with script , with “E” , and i dont know why.

#pragma strict
@script RequireComponent( AudioSource )

var papers : int = 0;
var papersToWin : int = 8;
var distanceToPaper : float = 2.5;

public var paperPickup : AudioClip;

var theEnemy : EnemyScript;




function Start() 
{
	Screen.lockCursor = true;
	
	// find and store a reference to the enemy script (to reduce distance after each paper is collected)
	if ( theEnemy == null )
	{
		theEnemy = GameObject.Find( "Enemy" ).GetComponent( EnemyScript );
	}
}


function Update() 
{ 
    //if ( Input.GetMouseButtonUp(0) ) // use E in editor as LockCursor breaks with left mouseclick
    if ( Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.E) ) 
    {
        //var ray = Camera.main.ScreenPointToRay( Input.mousePosition ); // always cast ray from center of screen
        var ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 ) );
        var hit : RaycastHit;
        if ( Physics.Raycast( ray, hit, distanceToPaper ) )
        {
            //if ( hit.collider.gameObject.tag == "Paper" )
            if ( hit.collider.gameObject.name == "Paper" )
            {
	            papers += 1;
	            //Debug.Log( "A paper was picked up. Total papers = " + papers );
	            
	            audio.PlayClipAtPoint( paperPickup, transform.position ); 
	            
	            Destroy( hit.collider.gameObject );
	            
	            // make enemy follow closer
	            theEnemy.ReduceDistance();
            }
        }
    }
}


function OnGUI()
{
    if ( papers < papersToWin )
    {
		GUI.Box( Rect( (Screen.width * 0.5) - 60, 10, 120, 25 ), "" + papers.ToString() + " Papers Collected" );
    }
    else
    {
		GUI.Box( Rect( (Screen.width/2)-100, 10, 200, 35 ), "All Papers Collected!" );
		// Application.LoadLevel( "sceneWin" );
    }
}

,To answer your question. Try using this in place of your reference to the key.

Input.GetKeyDown("e")

Hopefully this solves your issue. :slight_smile:

~ExplodingCookie

Here is a debugged version of your update function. You should see all of the messages in the console. I suggest commenting each one out once you have seen it, messaging the console will slow the game down.

This will allow you to isolate which line is not working. Post back once you have figured it out.

function Update() 
{ 
    Debug.Log("Update is working");
    if ( Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.E) ) 
    {
        Debug.Log("Inut is working");
        var ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 ) );
        var hit : RaycastHit;
        if ( Physics.Raycast( ray, hit, distanceToPaper ) )
        {
            Debug.Log("Raycast is working");
            if ( hit.collider.gameObject.name == "Paper" )
            {
                Debug.Log("Name checking is working");
                papers += 1;
                audio.PlayClipAtPoint( paperPickup, transform.position ); 
                Destroy( hit.collider.gameObject );
                theEnemy.ReduceDistance();
            }
        }
    }
}