Home > other >  Script types as generic how through GameObject. GetComponent scripting object
Script types as generic how through GameObject. GetComponent scripting object

Time:09-27

The following is my script base class (ViewModelBase is also the base class)
 
[RequireComponent (typeof (CanvasGroup)))
Public abstract class UnityGuiView : MonoBehaviour IView T: where ViewModelBase
{}


Found in the process of debugging GameObject. GetComponent (a); Unable to get scripting object
Here is one of the sample script
 
Public class LoginView: UnityGuiView
{}

CodePudding user response:

Can such a gameObject. GetComponent (a);
UnityGuiView generic class is not as components are added to the object, of course, to get less than wow.

CodePudding user response:

reference 1st floor tq_skye response:
can gameObject. GetComponent (a);
UnityGuiView generic class is not as components are added to the object, of course, get less than wow.


Each derived if so I was going to write it again I want to write a public method for component

CodePudding user response:

Pass GetComponent you don't want to get to the T type of object, it is not possible it has been in your LoginView generalization, so you can only access to the LoginView script (note the script is not ordinary class), in addition T can't be the script
  • Related