C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Data TypesA data type classifies various types of data, for example, string, integer, boolean, float, and the types of accepted values for that data type, operations that can be performed on the data type, the meaning of the data of that type can be stored. int: This data type is used to store 32 bits integer numbers. This data type stores positive or negative whole numbers. float: The float data type is used to store floating point numbers. The float data type is the default type of number in Unity. For Example: float points = 72.24; double: Double data type also stores floating point numbers, but it can hold larger size numbers than float. And it is not the default number type in Unity. For Example: double amount = 134434.23; bool: The bool data type is the short form of Boolean. This data type store true or false values. For example: bool chance = false; char: This data type stores a single character such as a number, letter, space, or special character. A char value should be written in single quotes. For example: char press = 'a'; string: This data type is used to store letters, numbers, and other special characters in the form of words or sentences. A string value should be written inside double quotes. For example: string CharacterName = "Ken Fighter"; ExampleLet's see one simple example: using System.Collections; using System.Collections.Generic; using UnityEngine; public class DataType: MonoBehaviour { int playerHealth = 100; float playerVelocity = 14.74f; string msg = "Welcome to the Game"; bool isGameOver = false; void Start() { Debug.Log("Initial Health : " + playerHealth); Debug.Log("Player's Volecity : " + playerVelocity + " km/h"); Debug.Log(msg); Debug.Log("Game Over: " + isGameOver); } // Update is called once per frame void Update() { } } Output:
Next TopicClasses
|