private void Awake()
{
LevelUP(); //C#에서는 이렇게 접근할 수 있습니다.
}
private void LevelUP()
{
print("Level Up!");
}
LevelUP() --루아에서는 이렇게 접근할 수 없습니다.
local function LevelUP()
print("Level Up!")
end
LevelUP() --루아에서는 선언부의 다음 줄에서만 접근할 수 있습니다.
//지역 변수
private int Number = 1;
private float FloatNumber = 1.5;
private string Message = "HelloWorld";
private bool State = false;
private GameObject obj = null;
private List<int> list = new List<int>();
//public 변수
public int Lv = 1;
//전역 변수
public static bool IsStartGame = true;
--지역 변수는 local로 선언합니다.
local Number = 1
local FloatNumber = 1.5
local Message = "HelloWorld"
local State = false
local obj = nil
local list = {}
--public 변수
Script.Lv = 1
--전역 변수는 local을 생략하고 선언합니다.
IsStartGame = true
private void Awake()
{
int sumValue = SomeFunc1(5, 10); //함수 호출
}
//지역 함수
private int SomeFunc1(int num1, int num2)
{
int result = num1 + num2;
return result;
}
//public 함수
public int SomeFunc2(int num1, int num2)
{
int result = num1 + num2;
return result;
}
//전역 함수
public static int SomeFunc3(int num1, int num2)
{
int result = num1 + num2;
return result;
}
--지역 함수
local function SomeFunc1(num1, num2)
local result = num1 + num2
return result
end
--public 함수
function Script:SomeFunc2(num1, num2)
local result = num1 + num2
return result
end
--전역 함수
function SomeFunc3(num1, num2)
local result = num1 + num2
return result
end
local sumValue = SomeFunc1(5, 10) --함수 호출
private void Sample()
{
List<int> objList = new List<int>();
objList.Add(1);
objList.Add(2);
objList.Add(3);
for(int i = 0; i < objList.Count; i++)
{
print(objList[i]);
}
}
local function Sample()
local objList = {}
table.insert(objList, 1)
table.insert(objList, 2)
table.insert(objList, 3)
for i = 1, #objList, 1 do
print(objList[i])
end
end
--if문
local Animal = "Dog"
if Animal == "Dog" then
print("Dog")
elseif Animal == "Cat" then
print("Cat")
else
print("Other Animal")
end
--for문
for i = 1, 5, 1 do
print(i)
break
end
--while문
while true do
print("Hello World")
break
end
local Count = 0
::case1::
if Count == 1 then
print("1")
goto case3
end
::case2::
print("2")
if Count == 0 then
Count = Count + 1
goto case1
end
::case3::
print("3")
GameObject character = transform.Find("Map/GameObject/Character").gameObject;
local character = Workspace.Character --계층간의 구분은 . 으로 표기합니다.
--추가한 변수가 Script 자신에게 있으면
local MoveSpeed = Script.MoveSpeed
local JumpSpeed = Script.JumpSpeed
--추가한 변수가 오브젝트나 다른 스크립트에 있으면
local Toy = Script.Parent
local Damage = Toy.Damage
local BulletSpeed = Toy.Bullet.BulletServerScript.BulletSpeed
Script.Lv = 1 --public으로 선언된 변수
function Script:DoSomething() --public으로 선언된 함수
print("DoSomething")
end
wait(1) --ServerScript1 다음에 동작할 수 있도록 지연 처리
Workspace.ServerScript1.Lv = 2 --public 변수 사용
Workspace.ServerScript1:DoSomething() --public 함수 호출
WelcomText = "" --전역으로 선언된 변수
function PrintMessage(msg) --전역으로 선언된 함수
print(msg)
end
wait(1) --ServerScript1 다음에 동작할 수 있도록 지연 처리
WelcomText = "Hello World!" --전역 변수 사용
PrintMessage(WelcomText) --전역 함수 호출
--스크립트 제일 윗줄에서 처리하면 Awake나 Start처럼 동작합니다.
print("HelloWorld!")
--바인딩 이벤트로 함수를 연결해서 구현할 수 있습니다.
local timer = 0
local function Update(updateTime)
timer = timer + updateTime
print(timer)
end
Game.OnUpdateEvent:Connect(Update)
--스태틱메쉬나 콜라이더의 Collision 프로퍼티가 true면 동작합니다.
local Cube = Workspace.Cube
--충돌영역에 대상이 있을때 호출됩니다.
--충돌영역 안에서 대상이 움직일때도 호출됩니다.
local function Collision(self, target)
if target == nil or not target:IsCharacter() then
return
end
print("Target : " .. target.Name)
end
Cube.Collision.OnCollisionEvent:Connect(Collision)
--콜라이더의 Collision 프로퍼티가 false면 동작합니다.
local BoxCollider = Workspace.BoxCollider
--충돌영역에 대상이 닿았을때 호출됩니다.
local function EnterTrigger(self, target)
if target == nil or not target:IsCharacter() then
return
end
print("Enter Target : " .. target.Name)
end
Cube.Collision.OnBeginOverlapEvent:Connect(EnterTrigger)
--충돌영역 안에 대상이 있을때 계속 호출됩니다.
local function UpdateTrigger(self, target)
if target == nil or not target:IsCharacter() then
return
end
print("Update Target : " .. target.Name)
end
Cube.Collision.OnOverlapUpdateEvent:Connect(UpdateTrigger)
--충돌영역에서 대상이 나갔을때 호출됩니다.
local function ExitTrigger(self, target)
if target == nil or not target:IsCharacter() then
return
end
print("Exit Target : " .. target.Name)
end
Cube.Collision.OnEndOverlapEvent:Connect(ExitTrigger)