"GetComponent<T>()" ,"GetComponent() as T","(T)GetComponent()"

what different from "GetComponent< T >()" ,GetComponent() as T and (T)GetComponent() ? please give me some example if you can!

GetComponent() is a Generic function which returns the component of type T as a T variable

GetComponent(Type) returns the component of the type you send as a parameter, and returns it as a Component

Since a Component reference is useless as is, you have to cast it to the specialized type you need - that's where the as cast and the c style cast come in

(T)GetComponent(Type) will do a normal cast, which will throw an exception if the cast fails (because the component isn't of type T)

GetComponent(Type) as T will do the other type of cast, which returns null if the cast fails

The as cast is faster, but it'll hide errors in your code, so it's generally best to stick to the normal cast if you use that - but better, stick to the generic version, as it doesn't need casting by yourself