-
Notifications
You must be signed in to change notification settings - Fork 0
/
Homework-session-1
125 lines (95 loc) · 2.93 KB
/
Homework-session-1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// LIBRARIES
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// CODE STRUCTURE
public class Session1Homework : MonoBehaviour
{
// 1.VARIABLES - data that is stored in your computer memory
// Declaring Variables: Scope (visibility) -- Type -- Name -- Value (optional)
// Numbers
public int myFirstWholeNumber = 1;
private int mySecondWholeNumber = 99;
public float myFirstDecimaNumber = 1.123456789012356f;
public double myFirstLongDecimaNumber = 1.123456789123456789123456;
// Text
private string myFirstWords = "Hello teacher! Happy to be teach this!";
public string mySecondWord = "Hello!";
// Logical (binary can be either true or false)
private bool myFirstBoolean = false;
public bool mySencondBoolean = true;
// 2.DATA STRUCTURES
// Declaring Data Structures: Scope -- Type -- Name -- Values (optional)
// Arrays
public int[] myWholeNumbersCollection = new int[5];
public float[] myDecimaNumbersCollection = { 1.3f, 2.5f, 3.0f };
// Lists
public List<int> myFirstIntList = new List<int>();
// 3.FUNCTIONS
// Declaring Functions: // Scope -- Type -- Variables -- Body (Instructions)
private float CalculatorSum (float _FirstNumber, float _SecondNumber)
{
float SumResult = _FirstNumber + _SecondNumber;
return SumResult;
}
//Start is called before the first frame update
void Start()
{
float SumResult = CalculatorSum(myFirstWholeNumber, mySecondWholeNumber);
Debug.Log("Adding two numbers result is: " + SumResult.ToString());
// Data in Arrays
// Changing the data
myDecimaNumbersCollection[0] = 2.8f;
myDecimaNumbersCollection[0] = 2.8f;
float SumResult12 = CalculatorSum(myDecimaNumbersCollection[0], myDecimaNumbersCollection[2]);
// Data in Lists
// Changing the data
myFirstIntList.Add(3);
myFirstIntList.Add(9);
myFirstIntList[0] = 5;
myFirstIntList[1] = 12;
// Retriving the data
Debug.Log(myFirstIntList[0]);
}
// Update is called once per frame
void Update()
{
}
}//
public class NatalieDictionaryTest : MonoBehaviour
{
void Start ()
{
List<NatalieTest> natalietest = new List<NatalieTest>();
natalietests.Add(new NatalieTest("awesome", 50));
natalietests.Add(new NatalieTest("cool", 100));
natalietests.Add(new NatalieTest("goodjob", 5));
natalietest.Sort();
foreach(NatalieTest test in natalietests)
{
Print(test.name + " " + test.power);
}
natalietests.Clear();
}
}
public class NatalieDictionaryTest : MonoBehaviour
{
void Start ()
{
Dictionary<string, NatalieTest> natalietests = new Dictionary<string, NatalieTest>();
NatalieTest nt1 = new NatalieTest("awesome", 50);
NatalieTest nt2 = new NatalieTest("cool", 100);
natalietests.Add("Happy", nt1);
natalietests.Add("cheerful", nt2);
NatalieTest cool = natalietests["cheerful"];
natalietests temp = null;
if(natalietests.TryGetValue("birds", out temp))
{
//success!
}
else
{
//failure!
}
}
}