Search Unity

Please help

Discussion in 'Works In Progress - Archive' started by samz, Apr 27, 2012.

  1. samz

    samz

    Joined:
    Mar 7, 2012
    Posts:
    107
    i attached my work.

    Basically i have 2 versions of a code. One is for the PC and when you hold UP arrow the character moves up. The other is for the phone that has a touch screen button. But when u hold this touch button it doesn't move :(

    Look in the PlayerControl script in the EnableMoveUp function. Thank you
     

    Attached Files:

    Last edited: Apr 27, 2012
  2. Paradigm-SW

    Paradigm-SW

    Joined:
    Dec 23, 2011
    Posts:
    402
    Can you post the code into the OP? Go into 'Go Advanced' in the edit screen, click the 'code' icon and copy/paste it.
     
  3. samz

    samz

    Joined:
    Mar 7, 2012
    Posts:
    107
    just focus on the Update and EnableMoveUp function, i THINK thats where problem is

    Code (csharp):
    1. @script RequireComponent( CharacterController )
    2.  
    3. var onscreentext : GUIText;
    4.  
    5. // Touch Screen Buttons
    6. var UP_Button : OnScreenButtons;
    7. var DOWN_Button : OnScreenButtons;
    8.  
    9. // Player
    10. var movement = Vector3.zero;
    11. var moveSpeed : float;
    12. var character : CharacterController;
    13. private var thisTransform : Transform;
    14.  
    15. // Ladder
    16. var LadderT : LadderTriggers;
    17. var LadderM : LadderTriggers;
    18. var LadderB : LadderTriggers;
    19. var canClimbUp : boolean = false;
    20. var canClimbDown : boolean = false;
    21. var ClimbingUp : boolean = false;
    22. var ClimbingDown : boolean = false;
    23. var grounded : boolean;
    24.  
    25. function Start()
    26. {
    27.     // Cache component lookup at startup instead of doing this every frame     
    28.     thisTransform = GetComponent( Transform );
    29.     character = GetComponent( CharacterController );   
    30. }
    31.  
    32. function OnEndGame()
    33. {
    34.     // Disable joystick when the game ends 
    35.     UP_Button.Disable();
    36.     DOWN_Button.Disable();
    37.  
    38.     // Don't allow any more control changes when the game ends
    39.     this.enabled = false;
    40. }
    41.  
    42.  
    43. //::::::::::::::::::::::::::::::  U P D A T E  :::::::::::::::::::::::::::::::::::::::
    44. function Update() {
    45. grounded = character.isGrounded;
    46.  
    47. // ------------ LADDER TRIGGERS
    48.     LadderControls();
    49.    
    50.     // Actually move the character
    51.     thisTransform.Translate( movement * Time.deltaTime );
    52. }
    53. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    54.  
    55.  
    56. //:::::::::::::::::::::::::::::  L A D D E R   C O N T R O L S  ::::::::::::::::::::::::::::::::
    57. function LadderControls() {
    58.     // Ladder Triggers
    59.     // On Bottom of Ladder
    60.     if ( LadderB.onBottom ) {
    61.         canClimbUp = true;
    62.         canClimbDown = false;
    63.     // On Middle of Ladder
    64.     }else if( LadderM.onMiddle  !LadderB.onBottom ) {
    65.         canClimbUp = true;
    66.         canClimbDown = true;
    67.     // On Top of Ladder
    68.     }else if( character.isGrounded  LadderT.onTop ) {
    69.         canClimbUp = false;
    70.         canClimbDown = true;
    71.     }
    72.        
    73.     // Enable UP
    74.     if( canClimbUp ){
    75.         EnableMoveUp();
    76.     // Enable UP and DOWN
    77.     }else if( canClimbUp  canClimbDown ){
    78.         EnableMoveUp();
    79.         EnableMoveDown();
    80.     // Enable DOWN
    81.     }else if( canClimbDown ){
    82.         EnableMoveDown();
    83.     }
    84. }
    85. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    86.  
    87.  
    88. //:::::::::::::::::::::::::::::  E N A B L E   M O V E - U P  ::::::::::::::::::::::::::::::::::
    89. function EnableMoveUp() {
    90.     if(UP_Button.position.y == 1  !LadderT.onTop){
    91.         onscreentext.text = "Should be moving up";
    92.         ClimbingUp = true;
    93.         movement = Vector3(0, 1, 0) * moveSpeed;
    94.     }else{
    95.         ClimbingUp = false;
    96.     }
    97.    
    98.     if(Input.GetKey("up")  !LadderT.onTop){
    99.         ClimbingUp = true;
    100.         movement = Vector3(0, 1, 0) * moveSpeed;
    101.     }else{
    102.         ClimbingUp = false;
    103.         movement.y = 0;
    104.     }
    105. }
    106. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    107.  
    108.    
    109. //:::::::::::::::::::::::::::  E N A B L E   M O V E - D O W N  ::::::::::::::::::::::::::::::::
    110. function EnableMoveDown() {
    111.     if(DOWN_Button.position.y == -1  !LadderB.onBottom){
    112.         onscreentext.text = "DOWN";
    113.         ClimbingDown = true;
    114.         movement = Vector3(0, -1, 0) * moveSpeed;
    115.     }else{
    116.         ClimbingDown = false;
    117.     }
    118.    
    119.     if(Input.GetKey("down")  !LadderB.onBottom){
    120.         ClimbingDown = true;
    121.         movement = Vector3(0, -1, 0) * moveSpeed;
    122.     }else{
    123.         ClimbingDown = false;
    124.         movement.y = 0;
    125.     }
    126. }
    127. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    128.