Scratch To Unity: Operators

Beginner Scratch Tutorial Unity

This post provides a handy reference guide to go from Scratch’s “Operators” category of code blocks to C# with Unity.

Studienkolleg in Germany (Prep Course)
Monday October 22, 2018

If you want to study in Germany as a non-EU international student, you must first check if your previous qualification is recognized at German universities. Every school-leaving certificate attained in your country must be compared and translated into German qualification terms otherwise it won’t be recognized. There is a limited list of foreign qualifications assessed […]

The post Studienkolleg in Germany (Prep Course) appeared first on Dua xe moto.

Code Blocks
Click on the picture of any of these Scratch code blocks to see how to write similar code statements in C#.

Earth Day (Ahem, Earth Week)
Wednesday April 24, 2019

We’re doing a giveaway! Earth Day 2019 has passed, but we’re extending our earth-friendly efforts all week long. On Monday, we held an Earth Day event on campus to encourage the LAFS community to clean up Hollywood. Thank you to all of those who participated and showed their support for our planet. While there are […]

The post Earth Day (Ahem, Earth Week) appeared first on Dua xe moto.

int score = 5 + 6; // 11
int age = score + 1; // 12
int total = score + age; // 23
score += 1; // 12
score++; // 13

int score = 10 – 5; // 5
int age = score – 1; // 4
int total = score – age; // 1
score -= 1; // 4
score–; // 3

int score = 3 * 5; // 15
int age = score * 2; // 30
int total = score * age; // 450
score *= 3; // 45

Apartments in Berlin
Wednesday December 12, 2018

The German capital Berlin is a national economic powerhouse, hosting countless medium to large and globally valued companies in different sectors. Berlin is a place of attractive tourism sites and many cultural gems. Its community is a mixture of different cultures and nationalities making for a rich and diverse society immersed in a unique lifestyle. […]

The post Apartments in Berlin appeared first on Dua xe moto.

int score = 10 / 3; // 3
double amount = 7.0 / 2.0; // 3.5
int total = score / score; // 1
score /= 3; // 1

int score = Random.Range(1, 11); // Could be one of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
float time = Random.Range(0f, 1f); // Could be any value between 0 (inclusive) and 1 (inclusive)
float amount = Random.value; // Could be any value between 0 (inclusive) and 1 (inclusive)

bool result = 10 > 3; // true
result = 3 > 10; // false

bool result = 10 < 3; // false
result = 3 < 10; // true

bool result = 10 == 10; // true
result = 10 == 3; // false

bool result = true && true; // true
result = true && false; // false
result = false && true; // false
result = false && false; // false

bool result = true || true; // true
result = true || false; // true
result = false || true; // true
result = false || false; // false

bool test = false; // false
test = !test; // true

string name = "Jon" + " the great!"; // "Jon the great!"
string firstName = "Jon";
string lastName = "Parham";
string fullName = string.Concat(firstName, " ", lastName); // "Jon Parham"
string[] fruits = { "banana", "grape", "strawberry" };
string allFruits = string.Join(", ", fruits); // "banana, grape, strawberry"

string name = "Jon";
string firstLetter = name.Substring(0, 1); // "J"
string secondLetter = name.Substring(1, 1); // "o"
string lastTwoLetters = name.Substring(1, 2); // "on"

string fruit = "apple";
int letterCount = fruit.Length; // 5

string fruit = "apple";
bool test = fruit.Contains("a"); // true
test = fruit.Contains("app"); // true
test = fruit.Contains("b"); // false

int mod = 10 % 3; // 1

float result = Mathf.Round(3.2f); // 3
result = Mathf.Round(3.7f); // 4

float result = Mathf.Abs(-3f); // 3

float result = Mathf.Floor(3.7f); // 3

float result = Mathf.Ceil(3.3f); // 4

float result = Mathf.Sqrt(4f); // 2

float result = Mathf.Sin(4f); // -0.7568025

float result = Mathf.Cos(4f); // -0.6536436

float result = Mathf.Tan(4f); // 1.157821

float result = Mathf.Asin(0.5f); // 0.5235988

float result = Mathf.Acos(0.5f); // 1.047198

float result = Mathf.Atan(0.5f); // 0.4636476

float result = Mathf.Log10(100f); // 2

float e = (float)System.Math.E;
float result = Mathf.Pow(e, 2); // 7.389056

float result = Mathf.Pow(10, 2); // 100

Links
Here are a few links that are relevant to this material and can help you dive a little deeper if you need more help.

Random
Mathf
String
Scratch Wiki for Operators Block

Summary
This should cover all of the code blocks in Scratch’s “Operators” category. If you have any questions about this reference guide feel free to ask below.
If you find value in my blog, you can support its continued development by becoming my patron. Visit my Patreon page here. Thanks!