Difference between GetComponent

What is the difference between

        Script sc = GetComponent<Script>();


        Script sc = Script();

thanks so much!

Script sc = GetComponent();

will get the component of a gameobject (Script is not a unity type)

for Example

 public GameObject FluffyBunny;

will return the Cuteness of a bunny from their bunnyAI script…

Not entirely sure what you mean by the second part though… Cause from just testing script is not a useable type in unity api Either that or its a custom class type…

They have nothing in common.

  1. Is the correct way to get a component. It’s a generic method call.

  2. won’t compile (have you even tried?).
    The left hand side is declaring a variable of type script. The right hand side is either that classes constructor, or a simple method. If it’s a constructor, the new keyword is missing. It’s also wrong, because that would ideed create a new Script instance, but none Unity would be aware of and especially none that’s attached to any gameobject, so it’s useless.
    If that was a method, it cannot be declared in the Script class because of the name’s ambiguity.
    If it was in another class it’s return type would need to be of type Script.