Selasa, 29 Oktober 2019

What is scripting in Unity?
Scripting tells our GameObjects how to behave; it’s the scripts and components attached to the GameObjects, and how they interact with each other, that creates your gameplay. Now, scripting in Unity is different from pure programming. If you’ve done some pure programming, e.g. you created a running app, you should realize that in Unity you don’t need to create the code that runs the application, because Unity does it for you. Instead, you focus on the gameplay in your scripts.
Unity runs in a big loop. It reads all of the data that’s in a game scene. For example, it reads through the lights, the meshes, what the behaviors are, and it processes all of this information for you.
If you think about television, where, for example in North America, you have 29.5 frame/sec, Unity needs to do the same thing. It’s running single discrete frames, one after another. You direct Unity with the instructions that you write in your scripts, and Unity executes them frame after frame as fast as it can.
Achieving a high frame rate means not only your game will look more fluid, but your scripts will also be executed more often, making controls more responsive.
What languages can you use in Unity?
A script must be attached to a GameObject in the scene in order to be called by Unity. Scripts are written in a special language that Unity can understand. And, it’s through this language that we can talk to the engine and give it our instructions.
The language that’s used in Unity is called C# (pronounced C-sharp). All the languages that Unity operates with are object-oriented scripting languages. Like any language, scripting languages have syntax, or parts of speech, and the primary parts are called variables, functions, and classes.
If you’re using a version of Unity until 2017.3, you’ll notice that it has a text editor called MonoDevelop: it can help us complete our code, it’ll let us know if we’re writing a wrong piece of code, and allows us to take shortcuts. Starting with 2018.1, you can also use Visual Studio for Unity Community, or other text editors such as Visual Studio, Notepad, or Sublime text.
Here’s a script with some sample code in it (based on the Coding in Unity for the Absolute Beginner tutorial):
sample code unity
As you can see, there are variables, functions, and classes.
What do these do?
Variables hold values and references to objects (you can see objects as “bigger” variables). They’re like a box that holds something for us to use. Variables start with a lowercase letter.
Functions are collections of code that compare and manipulate these variables. Functions start with an uppercase letter. We organise code in functions so that they can be easily reused multiple times in different parts of the program.
Classes are a way to structure code to wrap collections of variables and functions together to create a template that defines the properties of an object.
Scripting is primarily comparing these objects and their current states and values. It’s based on logic determining an outcome or resolution.
Variables
In Unity, the scripts start by laying out the tools that you need at the top, and this is usually by declaring variables. You can see the declared variables here with the visibility keyword “public” or "private" at the front, followed by a type, and a name.
variables in unity
When we’re declaring your variables there are several visibility types, but the two most important ones are public and private.
If you create a script with the above text in your code editor and then come back to Unity and assign the script to a GameObject, you’ll see that you can access and see the light variable declared as public in the Inspector, but you can’t see the private one. And that’s because what’s defined as “private” can only be accessed within this particular script, within this particular class.
If you make this public, then it’s accessible to other scripts and other classes, and can be changed in the Inspector from the Unity editor. So, that means other people can access it and change its value.
There are many reasons to choose between private or public. Private variables allow your code to be cleaner, since you know that the value of those variables can be changed only inside that class. This makes debugging and maintaining the code easier.
If you choose “public” , and you experience an issue, you need to look inside your whole codebase in order to track the source because any other object has access to that variable. However, if you want objects to communicate between themselves you need some variables (or functions) to be public.
Another important aspect of variables is the type. A type defines what kind of value is the variable holding in memory, e.g. it can be a number, text, or more complex types, like the ones in the image below: Transform, Light and Demo Script in the image below are in fact references to Components. Unity needs to know what type of object it is so that it knows how to handle it.
variables in unity inspector
Another important thing about variables is the name. The main thing that you need to remember about naming variables is that it can’t start with a number, and it can’t contain spaces. Therefore, there’s a style of writing the names. In C#, the naming convention is camelCase: you start with a lowercase letter and add words, without spaces, starting with a capital letter, e.g. "myLight".
When Unity compiles the script, it makes public variables visible in the editor. See the image below from the inspector.
demo script unity inspector
Functions
Scripts manipulate the variables by using functions. There are a number of functions that run automatically inside Unity. See below:
functions in unity
Awake is called only once when the GameObject with that component is instantiated. If a GameObject is inactive, then it will not be called until it is made active. However, Awake is called even if the GameObject is active but the component is not enabled (with the little checkbox next to its name). You can use Awake to initialize all the variables that you need to assign a value to.
Start - like Awake, Start will be called if a GameObject is active, but only if the component is enabled. For more information on the differences with Awake, see this video.
Update is called once per frame. This is where you put code to define the logic that runs continuously, like animations, AI, and other parts of the game that have to be constantly updated.
FixedUpdate is when you want to do physics work.
As you can see, there’s Fixed Update and Update and in our Scripting tutorials section, you can learn how to effect changes every frame with the Update and FixedUpdate functions, and their differences.
LateUpdate is a function that’s similar to Update, but LateUpdate is called at the end of the frame. Unity will look at all of the game objects, find all of the Updates, and call the LateUpdates. This is good for things like the camera. Let’s say you want to move a character in your game. And then he’s bumped into by another character and ends up in a different position. If we move the camera at the same time as the character, there would be a jiggle, and the camera wouldn’t be where it needs to be. So, basically, it’s a second loop that comes in very handy.
Writing functions
When writing a function, remember that functions start with the returned type of the function at the beginning, followed by the name of the function, and then the parameters in the parentheses (if any). Function names start with a capital letter and the body of the function goes between the curly brackets. Here’s an example on how to write a function:
writing functions unity
How do we call this function?
function-in-unity
Functions can do calculations and then return a value. You can ask a function to do something, process the information, then return an answer. If you use the type "void", then they are not returning anything.
Classes
Classes are collections of these variables and functions. For example, this script is a class:
class example in Unity
Bear in mind that the class name must match the file name of the C# script for it to work. And then to be attached to a GameObject, it has to derive from another class called MonoBehaviour which is automatically put there for you when you first create a script. Classes can also be public or private.
In Unity, if you create a custom class, like in the example below, you have to ask it to serialize it. This means that it will be converted into simple data that Unity can look at in the inspector. When you do that, it’ll see that you have the class will appear in the inspector.
classes in unity example
Variables, functions, and classes are just the basics of starting with coding in Unity. Check out the Learn section, you can find a bunch of useful scripting tutorials that will help you go learn about programming from scratch, then progress to create detailed code for your projects.

Selasa, 17 September 2019

I9

i9 Terbaru!

APA SAJA KELEBIHAN DAN KEKURANGANNYA?
Intel i7 sudah beberapa tahun terakhir menjadi seri tertinggi pada processor untuk konsumen, tapi itu akan berubah karena Intel sekarang sudah ada Intel i9 yang akan menggantikannya.
Bersamaan dengan peluncuran Intel Core i9, Intel juga mengumumkan sebuah keluarga processor terbaru yang disebut X-series. X-series ini menggunakan socket terbaru yaitu LGA 2066, yang memiliki chipset X299 (pengganti X99 yang sudah lama beredar) dan tentunya kalian harus membeli motherboard baru untuk menggunakan X-series tersebut.
Intel Core X Series Processor Intel Core X Series Processor

Intel Core i9 hanya untuk PC
Intel hanya meluncurkan X-series ini untuk High-end Desktop Computers atau gampangnya sebut saja PC High-End. Dan mereka (Intel) telah mengumumkan tidak akan membawa Core i9 untuk Laptop.
Apakah Core i9 akan lebih cepat dibanding Core i7?
Yang membedakan Core i9 adalah jumlah core nya, dimana untuk seri paling ‘bawah’ memiliki jumlah core 10 dan yang paling ‘atas’ memiliki 18 core. Dan semua itu memiliki teknologi HyperThreading yang berarti mereka memiliki antara 20 Threads sampai 36 Threads.
Dan untuk menjawab pertanyaan apakah i9 akan lebih cepat dibanding i7 adalah YA secara teori. Kenapa secara teori? Karena semakin banyak core yang kalian miliki maka lebih banyak task yang dapat kalian jalankan bersamaan.
Tentu saja yakin jika kalian hanya menggunakan untuk tugas-tugas seperti biasa saja (ms office sampai bermain game berat sekalipun) kalian tidak akan menggunakan semua core tersebut. Karena semua software-software yang beredar saat ini tidak dibuat untuk menggunakan core sebanyak itu.
Untuk saat ini mungkin Intel Core i9 akan lebih berguna dimasa yang akan datang dibandingkan masa sekarang, atau ketika para pembuat software benar-benar memanfaatkan banyaknya jumlah core tersebut. Untuk saat ini Core i9 hanya akan lebih cepat untuk beberapa hal saja (melakukan render Video, Multi-Tasking yang benar-benar berat).
Cukup untuk penjelasan Awal sekarang kita akan masuk ke dunia yang lebih teknis.

Fitur – Fitur yang ada pada X-series
Turbo Boost Max 3.0
Intel Turbo Boost Max 3.0Intel Turbo Boost Max 3.0
X-series juga membawa teknologi Turbo Boost Max 3.0 untuk semua processor-nya. Ini merupakan Teknologi advanced dari Intel Turbo Boost yang sudah ada. Dengan teknologi baru ini, processor akan mengindentifikasi mana 2 buah core ter ‘kencang’ dan menggunakan mereka untuk mengerjakan fungsi task yang terpenting. Tentu saja itu hanya untuk sementara, terjadi ketika processor benar-benar “kewalahan” mengerjakan berbagai tugas (task). Dan ini pertama kalinya Turbo boost men-support 2 buah core, karena sebelum-sebelumnya hanya men-support 1 core saja.

Menyeimbangkan Hirarki dari Cache
Rebalancing Cache Hierarchy Intel X SeriesRebalancing Cache Hierarchy Intel X Series
Memang agak membingungkan hal ini bagi yang belum tahu tentang kegunaan cache pada processor.
Cache Processor merupakan salah satu penyebab yang bisa membuat PC / Laptop kita menjadi lambat. Karena Cache di processor ini bekerja pada level yang sangat dasar dan bisa dibilang merupakan “RAM untuk processor sendiri” karena setiap core memiliki tempat menyimpan data untuk melakukan tugas-tugas yang biasa berulang, mereka tidak perlu melakukan perhitungan ulang setiap kali tugas-tugas tersebut dikerjakan lagi. Tentu saja lebih banyak Cache lebih baik (semakin cepat) performanya.
Pada seri Core i9, Intel telah melipat-empatkan jumlah cache yang terdapat pada masing-masing core, tetapi mereka men-setengahkan Shared Cache (cache yang digunakan untuk semua core). Intel mengklaim hal ini akan memberikan performa yang lebih baik karena cache yang terdapat masing – masing core memiliki latency (waktu yang dibutuhkan processor mengakses cache tersebut) yang lebih kecil. Yang berarti data akan mengalir dengan lebih cepat antara cache dan core.

4 Channel DDR4 RAM dan Intel Optane
Core i9 mendukung Quad-Channel DDR4 RAM dan akan memberimu potensi menggunakan RAM sampai 128GB.
Selain itu processor ini juga akan mendukung Intel Optane yang secara singkat meningkatkan performa HDD menjadi seperti SSD.

Kekurangan
Tentunya dengan segala kelebihan tersebut pasti ada kekuranganya.
Selain Processor bagus agar menunjang performanya tentu saja dibutuhkan hardware lainnya yang bagus juga, dan semua itu memerlukan investasi yang tidak sedikit, setidaknya agar kalian mendapat potensi maksimal dari Core i9 ini kalian harus menyiapkan uang untuk membeli Motherboard baru, RAM DDR4 serta Intel Optane untuk menambah performa agar maksimal.

What is scripting in Unity? Scripting tells our GameObjects how to behave; it’s the scripts and components attached to the GameObjects,...