728x90
float rnd = Random.Range(0.0f, 0.5f);
0.0f~0.5f ์ฌ์ด์ ์ซ์๋ฅผ ๋๋ค์ผ๋ก ์์ฑํ์ฌ ๋ณ์ rnd์ ๋ฃ์ด์ฃผ๋ ์ฝ๋์ด๋ค.
<ํ์ฉ์์>
์๋ ์์ค์ฝ๋๋ A๋ฅผ ๋๋ฅผ ์,
0.0~0.5 ์ฌ์ด์ ๋์๋ฅผ ์์ฑํ์ฌ ๊ฐ์ ๋ณ์ rnd์ ์ ์ฅํ๊ณ
์ค๋ธ์ ํธ์ transform.position์ Vector3ํ z๊ฐ์ ๋์ ํด ์์น๋ฅผ ๋ฐ๊พธ๋ ์ฝ๋
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class studyScript : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
float rnd = Random.Range(0.0f, 0.5f);
this.transform.position = new Vector3(0.0f, 0.0f, rnd); //transform.position์ ๊ฒ์ ์ค๋ธ์ ํธ์ ์์น๋ฅผ ๋ํ๋ด๊ณ ์ฌ๊ธฐ์๋ Vector3ํ ๊ฐ์ ๋์
ํ ์ ์๋ค.
}
if (Input.GetKeyDown(KeyCode.B))
{
float rnd = Random.Range(0.0f, 360.0f);
this.transform.rotation = Quaternion.Euler(rnd, 0.0f, 0.0f);//transform.rotation์ ๊ฒ์ ์ค๋ธ์ ํธ์ ํ์ ์ ๋๋ฅผ ๋ํ๋ด๊ณ ์ฌ๊ธฐ์๋ Quaternion.Euler ๊ฐ์ ๋์
ํ ์ ์๋ค.
}
if (Input.GetKeyDown(KeyCode.C))
{
float rnd = Random.Range(1.0f, 1.5f);
this.transform.localScale = new Vector3(rnd, rnd, rnd);//transform.localScale์ ๊ฒ์ ์ค๋ธ์ ํธ์ ํฌ๊ธฐ๋ฅผ ๋ํ๋ด๊ณ ์ฌ๊ธฐ์๋ Vector3ํ ๊ฐ์ ๋์
ํ ์ ์๋ค.
}
}
}
728x90
'Unity > Unity(๊ธฐ์ด)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Unity์์ this์ ์๋ฏธ (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 |