- Home /
How to use unity scripting api?
How we use unity scripting API when programing?is API like standard library ? How API work? example how to use it?
Answer by tanoshimi · Jul 12, 2017 at 06:17 AM
The API contains all the methods to achieve anything through code in Unity. It essentially is Unity - certainly from a programmer's perspective. https://unity3d.com/learn/tutorials
If @SohailBukhari answer is wrong, than this is wrong as well -.-. The Unity API only coveres methods / classes / types defined in the UnityEngine.dll. (and lately all the extension dlls like UI, networking, ...). Anything else (mscorlib.dl, System.dll, ...) is part of the mono framework which can also be used but is not part of the Unity API.
So if you're not too nitpicky both answers are correct with $$anonymous$$or mistakes / ambiguities so i give an upvote to both ^^.
Answer by SohailBukhari · Jul 12, 2017 at 06:26 AM
Application program interface (API) is a set of routines, protocols, and tools for building software applications. An API specifies how software components should interact. Additionally, APIs are used when programming graphical user interface (GUI) components. A good API makes it easier to develop a program by providing all the building blocks. A programmer then puts the blocks together.
Best explanation of API https://en.wikipedia.org/wiki/Application_programming_interface
MonoBehaviour is the API, MonoBehaviour is the base class from which every Unity script derives.
Edited: (thanks to @Hellium)
When you use C# "as unity script to interact with unity gameobjects", then you must explicitly derive from MonoBehaviour.
Yes you do not need all of c# classes to be drived from MonoBehaviour (When you do not need to interact with GameObjects) When you use UnityScript (a type of JavaScript), you do not have to explicitly derive from MonoBehaviour.
Note: There is a checkbox for disabling MonoBehaviour on the Unity Editor. It disables functions when unticked. If none of these functions are present in the script, the Editor does not display the checkbox. The functions are:
Awake()
Start()
Update()
FixedUpdate()
LateUpdate()
OnGUI()
OnDisable()
OnEnabled()
Basically we designed API in the way that a programmer use its public methods in his script and all private members are hidden from the user, we call only API and get our desired result without doing anything.
Lets take an example we want to use String API Represents text as a series of Unicode characters.
Unity uses the .Net System.String class for strings.
Note: In c# string is an alias for System.String. This means that you can use either string or String in your code (if you have added using System to the top of your script.) Every component has its own API in the unity engine.
You are wrong on many levels :
$$anonymous$$onoBehaviour does not represent the Unity API
You don't have to make your classes derive from
$$anonymous$$onoBehaviour
when using C#. You can have pure C# classes or make your class extend a Unity component or theScriptableObject
class orEditor
class or many, many othersUnity does not use .Net, but its open source version : $$anonymous$$ono
And a script with the Awake method only won't have a checkbox in the Inspector. It will be called once the gameobject is enabled
I wouldn't be that harsh as most information provided is not wrong, just incomplete. "The Unity API" does of course cover all classes that Unity provides to you (everything defined inside the UnityEngine.dll). However $$anonymous$$onoBehaviour is the main link between Unity and a script. Note that he said script, not class. A script file in Unity is most the time used as Component. Any other use of classes are not related to the Unity API at all since it's just plain C#.
Yes Awake doesn't belong to that list of methods, however that is not his fault as this is the list copied from the docs. So it's just another case where the documentation has it wrong -.-
While technically it's right that Unity doesn't use .NET (at least on most platforms), $$anonymous$$ono is ment to be a 100% compatible replacement (which it probably never reach). The mono project site even states:
$$anonymous$$ono is an open source implementation of $$anonymous$$icrosoft's .NET Framework
this technically makes mono being an implementation of the .NET framework.
As i said most he said is not plain wrong, just incomplete or with a limited view.
"There is a checkbox for disabling $$anonymous$$onoBehaviour on the Unity Editor. It disables functions when unticked. If none of these functions are present in the script, the Editor does not display the checkbox". i mean our $$anonymous$$onoBehaviour won't have a checkbox next to it in the inspector if it doesn't have any of the per-frame methods, like Update, FixedUpdate, OnGUI, etc.
@Hellium help us to learn.
$$anonymous$$onoBehaviour does not represent the Unity API. So unity tells it wrong as scripting API?
You don't have to make your classes derive from $$anonymous$$onoBehaviour? Who asked you to do that? $$anonymous$$onoBehaviour is the base class from which every Unity script derives (its not about all of your classes when writing any script in unity)
Why you want to prove it wrong that Unity uses System.String of .Net framework. It actually does via $$anonymous$$ono (As $$anonymous$$ono is an open source implementation of $$anonymous$$icrosoft's .NET Framework)
All three points are wrong. . We are supposed to be supportive here not lawyer to prove others wrong by manipulations. I am sorry for this but I have been unable to put my request with better wording.
As indicated by @Bunny83, the Unity API is all the classes, the functions, interfaces, .... defined in UnityEngine.dll and UnityEditor.dll. The $$anonymous$$onoBehaviour class is the base class of your custom class you want to make as a component to attach to a gameobject. But a "Unity script" (which means everything and nothing) can derive from
Editor
for example.SohailBukhari indicated that "When you use C#, you must explicitly derive from $$anonymous$$onoBehaviour.", which is false (see point #1)
I am simply fixing what's wrong in SohailBukhari's answer. I apologize if it has been interpreted as too rudely.
Are you a bot? This answer seems like some arbitrarily copy-pasted paragraphs from Wikipedia, and the Unity script reference, and here, and really doesn't make much sense.
Aside from the issues @Hellium has already mentioned: "$$anonymous$$onoBehaviour is the API"... "we want to use String API"... ? So you want to use the String $$anonymous$$onobehviour? This really makes no sense. I don't see how your mention of GUI components is at all relevant to the question. Private members are not "hidden from the user" - they are inaccessible to other classes, and there is no OnEnabled()
function - it's OnEnable()
.
Lets take an example we want to use String API Represents text as a series of Unicode characters.`String API example means`
example = String.trim(example);
example = String.replace(example, 'a', 'b');
basically String.trim(example)
is method of String API class which we use to trim.
I think you understand correctly, but your ter$$anonymous$$ology is wrong: Trim and Replace (note capital letters) are methods of the String class. There is no "String API Class".
hello. normally what line always appear unity api word?is it method signature line? any other line?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
get the duration of the curently playing clip of the timeline? 1 Answer
Detect if build target is installed 1 Answer