I'm curious now: Is there a certain way that I need to code, to bring in the Rigidbody component? I was looking at the que…

Forum Archive I'm curious now: Is there a certain way that I need to code, to bring in the Rigidbody component? I was looking at the que…

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #4761
    Jasmine Wongus
    Participant

      I’m curious now: Is there a certain way that I need to code, to bring in the Rigidbody component? I was looking at the question from five months ago, and peered at the blog regarding it.

      #23029
      Jonathan Gonzalez
      Participant

        If you’re going to use something within the Rigidbody component you’ll need to use GetComponent, preferably in the Start function. So if you’re adjusting the speed/gravity of that rigidbody via code then you’ll use GetComponent first to cache that object. If you’re not doing any of that it’s not necessary. So in the script shown in the video it’s not necessary since we’re not using anything specific to rigidbodies, but just using it as a projectile. 

        #23030
        Jasmine Wongus
        Participant

          Ahhh, okay. Thanks for clarifying, Jonathan!

          #23031
          Jonathan Gonzalez
          Participant

            Just to clarify a bit as it can be confusing. Unity will automatically cache these commonly used components for you. In general if you want to access something within a script, you need to tell Unity to Get that component, or “Get that script” so you can access it. That’s all you’re doing with GetComponent. With a Rigidbody it’s not really necessary at the moment to do that since Unity does that in the background, although they have required it in the past (like in Unity 5.0), but not at the moment. 

            #23032
            Jasmine Wongus
            Participant

              Oh, that makes even more sense! Thanks! 😀

            Viewing 5 posts - 1 through 5 (of 5 total)
            • The topic ‘I'm curious now: Is there a certain way that I need to code, to bring in the Rigidbody component? I was looking at the que…’ is closed to new replies.