728x90
๋ณดํต ์คํฌ๋ฆฝํธ๋ ์ค๋ธ์ ํธ์ ๋ฃ๊ณ ์ด๋ค.
this๋ ํด๋น ์คํฌ๋ฆฝํธ๋ฅผ ํฌํจํ๊ณ ์๋ ์ค๋ธ์ ํธ ๊ทธ ์์ฒด๋ฅผ ์๋ฏธํ๋ค.
๊ทธ๋ฌ๋ฏ๋ก ์๋ ์์ 1๊ณผ ์์ 2๋ฅผ ์์ฑํ๋ฉด, ๊ฒฐ๊ณผ์ ์ผ๋ก ๋๊ฐ์ ์๊ฐ์ ํจ๊ณผ๊ฐ ๋ํ๋๋ค.
<์์ 1>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class studyScript : MonoBehaviour
{
void Update()
{
float x = Input.GetAxis("Horizontal") * 0.05f;
float y = Input.GetAxis("Vertical") * 0.05f;
this.transform.Translate(new Vector2(x, y));
}
}
<์์ 2>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MOVE : MonoBehaviour
{
Transform tr;
void Update()
{
tr = GetComponent<Transform>();
float x = Input.GetAxis("Horizontal")*0.05f;
float y= Input.GetAxis("Vertical") * 0.05f;
tr.Translate(new Vector2(x, y));
}
}
728x90
'Unity > Unity(๊ธฐ์ด)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Unity ๋์ ์์ฑ์ Random.Range๋ฅผ ํ์ฉํ์ (0) | 2021.08.17 |
---|---|
unity ์ํ์ข์ฐ ์ฝ๋ 2๊ฐ์ง Input.GetKey vs Input.GetAxis ๊ทธ๋ฆฌ๊ณ Translate() ํจ์์ ํ์ฉ (0) | 2021.08.12 |
์ ๋ํฐ Quaternion (0) | 2021.06.05 |
[์ ๋ํฐ] get set ํ๋กํผํฐ Property(์์ฑ) (0) | 2021.05.23 |
[์ ๋ํฐ] Debug.Log์ Debug.LogFormat ํ์ฉ. ์ด๋ค ๊ฒ์ ์จ์ผํ ๊น? (0) | 2021.05.22 |