Search Unity

how to use class in programming c# with unity?

Discussion in 'Scripting' started by james82, Sep 10, 2017.

Thread Status:
Not open for further replies.
  1. james82

    james82

    Joined:
    Apr 9, 2016
    Posts:
    14
    how to use 'class' in programming c# with unity? 1. 'class' that we created ( example :
    Code (CSharp):
    1. public class PlayerData
    in PlayerData.cs. 2. 'class' exist in unity class library ( example : UnityEngine.Sprite ). what different between using class ? how to understand it ? what i create a 'class'.cs for? how it work? how to learn create a class file and use it? how to use class in unity class library?
     
  2. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    If you want to use a Class sytem in unity, you can use [System.Serializable] to make tbis happen

    Code (CSharp):
    1.     [System.Serializable]
    2.     public class MyClass
    3.     {
    4.         public string name;
    5.         public int number;
    6.  
    7.     }
    8.  
    9.     public MyClass myClass; // makes it visible in inspector
    You can put this in any script (just before any methiods such as Start/Update
     
  3. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
Thread Status:
Not open for further replies.