Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Scritp bug 2 different scene

Discussion in 'Scripting' started by Cuttyflame, Oct 21, 2014.

  1. Cuttyflame

    Cuttyflame

    Joined:
    Oct 7, 2014
    Posts:
    3
    So first hi.

    I have finished the 2d infinite runner recently and i just have think to add 2 mode. So i create my second scene for the 2 mode, but when i have import the 2d charachter, my script start to bug at line 38.
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(PlatformerCharacter2D))]
    4. public class Platformer2DUserControl : MonoBehaviour
    5. {
    6.     private PlatformerCharacter2D character;
    7.     private bool jump;
    8.  
    9.  
    10.     void Awake()
    11.     {
    12.         character = GetComponent<PlatformerCharacter2D>();
    13.     }
    14.  
    15.     void Update ()
    16.     {
    17.         // Read the jump input in Update so button presses aren't missed.
    18. #if CROSS_PLATFORM_INPUT
    19.         if (CrossPlatformInput.GetButtonDown("Jump")) jump = true;
    20. #else
    21.         if (Input.GetButtonDown("Jump")) jump = true;
    22. #endif
    23.  
    24.     }
    25.  
    26.     void FixedUpdate()
    27.     {
    28.         // Read the inputs.
    29.         //bool crouch = Input.GetKey(KeyCode.LeftControl);
    30.         #if CROSS_PLATFORM_INPUT
    31.         //float h = CrossPlatformInput.GetAxis("Horizontal");
    32.         #else
    33.         float h = Input.GetAxis("Horizontal");
    34.         #endif
    35.  
    36.         // Pass all parameters to the character control script.
    37.         // start to bug here //
    38.            character.Move ( 1, false, jump );
    39.  
    40.         // Reset the jump input once it has been used.
    41.         jump = false;
    42.     }
    43. }
    44.  
    i am sure it cause i have 2 same character in different scene but what can i do to correct the bug?
     
    Last edited: Oct 21, 2014