Search Unity

C# script don't load interface

Discussion in 'Scripting' started by Kyo620724, Sep 14, 2020.

  1. Kyo620724

    Kyo620724

    Joined:
    Sep 14, 2020
    Posts:
    5
    Hi all,

    I am a newbie and watching roll a ball tutorial to learn Unity. When I was following the YouTube video, I was stuck with the script part.

    At step 2.4 2:35, the lady open the editor and visual studio load the MonoBehaviour automatically (image attached below). On the right hand side, the Solution 'Rollaball' loaded as project.

    However, my editor MonoBehaviour shows as white Text and no solution loaded. Although there are no error, my RollABall project isn't working.

    Can tell me why? Do I miss any step?

    2020-09-14 01_13_26.png

    2020-09-14 01_15_22.png
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    First make sure that Visual Studio is set as external code editor.
    https://code.visualstudio.com/docs/other/unity

    Afterwards Intellisense should work. To test this write gameObject. (with dot) into your Start() method and see if it offers you some auto-completion options such as gameObject.transform. If that's working Unity and VS should be linked properly and everything should be working without problems. The rest should just be a visual difference, which may be due to some theme you use? So maybe something along those lines helps?
    https://www.reddit.com/r/Unity3D/comments/2r8amv/unity_visual_studio_with_highlighting_for_unity/

    I have no idea if the solution explorer or the specific names displayes there are important for anything tho. I have collapsed it and only use VS through Unity. Maybe someone with more VS experience can comment on that.
     
  3. Kyo620724

    Kyo620724

    Joined:
    Sep 14, 2020
    Posts:
    5
    Thank you! Intelligence is working now.

    I am testing the ball which is still not moving. Since I am new to Unity, I want to follow the video step by step. My concern is InputActions. When I was following the tutorial at step 2.3, I found little different between the video and mine. Is there anyway to debug this issue?

    2020-09-14 12_03_48-Window.png
     
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    How old is the tutorial? If it is using the new input system i'm not familiar with that yet. Otherwise you can get the input vector for horizontal and vertical inputs as follows, but that doesnt really help you for following the tutorial step by step.
    Code (CSharp):
    1. Vector2 inputVector = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
    Either way a link to the actual tutorial would be helpful as well.

    One problem i see with your code is that OnMove is not getting called from anywhere. If that's the case the ball never receives anything but 0 force.

    Last but not least, please use code tags for posting code examples. It's the <> button here in the text editor. Makes it easier to work with than screenshots.
     
  5. Kyo620724

    Kyo620724

    Joined:
    Sep 14, 2020
    Posts:
    5
    Hi Yoreki,

    Here is the tutorial link: https://learn.unity.com/tutorial/mo...8f1bedbc2a0020e51f0d#5f107d5cedbc2a001f705c15

    I stuck at step 7.Apply force to the Player. At this step, I through it caused by the Intellisense issue which was fixed. Now, I tried both step 7 & 8. None of them can make the ball move.

    By this reason, I added some debug logs to test my script. Based on the console message, my script Start method get called, but OnMove method isn't. The FixedUpdate method has MovementX 0 and MovementY 0.

    Therefore, I deleted Player Input and redo step 3 - Add a Player Input component. By adding new input actions, I can see error message: NullReferenceException: SerializedObject of SerializedProperty has been Disposed.

    Again, I ran the project and ball still not moving. Same issue - OnMove method is not working and MovementX 0 and MovementY 0.
    2020-09-14 17_11_23-Window.png

    2020-09-14 17_16_53-Window.png
     
  6. Kyo620724

    Kyo620724

    Joined:
    Sep 14, 2020
    Posts:
    5
    I fix the NullReference issue by downgrade the Input System package to Preview 6. Then I redo Player Input.

    Unfortunately, ball still not moving.

    2020-09-16 00_39_14-Roll-a-Ball - Microsoft Visual Studio.png
     
  7. Kyo620724

    Kyo620724

    Joined:
    Sep 14, 2020
    Posts:
    5
    Issue resolved.