Search Unity

Question public Rigidbody rb;

Discussion in 'Scripting' started by danielberezin199, Jun 29, 2021.

  1. danielberezin199

    danielberezin199

    Joined:
    Jun 29, 2021
    Posts:
    3
    Hello I am trying to make a game for the first time so any help would go a long way I am following a totorial


    And am stuck trying to make public Rigidbody rb; work. What I think is supposed to happen is a small box appears under the script and I drag in Rigidbody but the box never comes up here is the code:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Pmov : MonoBehaviour{
    4.  
    5.     public Rigidbody rb;
    6.  
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.         Debug.Log("Hello World");
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.        
    17.     }
    18. }
    Another thing I think I should mention is in the tutorial both Rigidbody rb; and Debug are in orange text however both are in white for me.
     
  2. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Do you have any errors in the console?
     
  3. danielberezin199

    danielberezin199

    Joined:
    Jun 29, 2021
    Posts:
    3
    nothing in the console
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Almost certainly there is either:

    1. an error somewhere in some piece of code (see below). All errors must be fixed before any scripts can be attached.

    2. this script is not named PRECISELY
    Pmov.cs
    , including capitalization

    Is that really what Brackey's called it? Pmov seems unlikely to me, but maybe...

    Make sure your log console selector buttons are enabled. See this graphic:

    https://forum.unity.com/threads/cant-add-script-component.632746/#post-4239121

    https://forum.unity.com/threads/update-function-not-working.953477/#post-6215873

    ALSO... here's some notes to speed you along your journey:

    How to do tutorials properly:

    Tutorials are a GREAT idea. Tutorials should be used this way:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation generally ends in disaster. That's how software engineering works. Every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly. Fortunately this is the easiest part to get right. Be a robot. Don't make any mistakes. BE PERFECT IN EVERYTHING YOU DO HERE.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
  5. danielberezin199

    danielberezin199

    Joined:
    Jun 29, 2021
    Posts:
    3
    Thank you very much! I got it working but I don't really know how I changed the name to exactly what Brackey used I didn't know that it would be an issue and I added then deleted rb.useGravity = false and that made it come up so thanks for the help also, I like your dog and thanks for the tips on learning,
     
    Kurt-Dekker likes this.
  6. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,648
    That should not have solved your issue. My best guess is that you didn't save your file, and so Unity didn't register that there was a change. Make sure you save your files whenever you make a change. If you're using Visual Studio or another similar IDE, there's usually a star or something that tells you if the file has been saved or not.

    upload_2021-6-29_12-28-20.png