Search Unity

calling between classes [static and new method]

Discussion in 'Scripting' started by muniraj_143, Feb 21, 2017.

  1. muniraj_143

    muniraj_143

    Joined:
    Oct 2, 2015
    Posts:
    23
    I am trying to access method between 2 classes.
    What is the difference between making the method static and accessing by object (using new method)
    As i am not able to get the reference.
    Thanks in advance.
     
  2. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    A public static class, means that there can only be 1 class. its an easy way to access a class like a gamemanager.

    accessing by object. i assume you mean getcomponent<>. this is more costly at runtime.

    does that help?
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Why aren't you able to get the reference?

    It's not a good idea to just throw statics around, as a static implies a global state (or rather should be stateless, stateful statics are usually a code smell).
     
  4. muniraj_143

    muniraj_143

    Joined:
    Oct 2, 2015
    Posts:
    23
    Thanks for the reply. I am developing UI for Xbox (UWP). I am trying to communicate between xaml and unity, that is why it is not easy.