Search Unity

Slender pages

Discussion in 'Scripting' started by Isikuo, Jul 26, 2014.

  1. Isikuo

    Isikuo

    Joined:
    Jul 23, 2014
    Posts:
    13
    I am using Alucard's slender guide to make a game similar to it. I am using the spherecast script he provides in a video, because the link to his scripts just crashes if I open it in Internet explorer on any computer I use. Using the script there are no errors but pressing E or clicking does not pick up a page. I try from every angle, very close up and a bit far back, I even messed with the distance and changed it to 2, 2.5, 5, 5.5. I do not understand what is wrong. It'd help if someone used the script in their Unity and tried to figure out what's wrong.
    Here it is:
    Code (CSharp):
    1. #pragma strict
    2. var papers : int = 0;
    3. var papersToWin : int = 4;
    4. var distanceToPaper : float = 5.5;
    5. var sphereRadius : float = 1.0;
    6. function Update()
    7. {
    8. if ( Input.GetMouseButtonDown(0) || Input.GetKeyDown( KeyCode.E ) )
    9. {
    10. var hit: RaycastHit;
    11. var rayOrigin : Ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height *0.5, 0 ) );
    12. if ( Physics.SphereCast( rayOrigin, sphereRadius, hit, distanceToPaper ) )
    13. {
    14. Debug.Log( "Test" );
    15. if ( hit.collider.gameObject.name == "Paper" )
    16. {
    17. Debug.Log( "Tests" );
    18. papers += 1;
    19. Destroy( hit.collider.gameObject );
    20. if ( papers == papersToWin )
    21. {
    22. Debug.Log( "You have collected all of the Papers !" );
    23. }
    24. }
    25. }
    26. }
    27. }
    EDIT: Also the cubes are named Paper, forgot to mention that.