![]()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mortar : MonoBehaviour
{
public GameObject mortarshell;
public Transform muzzle;
public Transform mortarRange;
private Transform c;
List<GameObject> mortarshellList = new List<GameObject>();
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void Fire()
{
float a = Random.Range(-1.0f, 1.0f);
float b = Random.Range(-1.0f, 1.0f);
GameObject temp = Instantiate(mortarshell, muzzle.position, Quaternion.identity);
mortarshellList.Add(temp);
for(int i=0;i<mortarshellList.Count;i++)
{
mortarshell _mortarshell = mortarshellList[i].GetComponent<mortarshell>();
_mortarshell.start = muzzle;
_mortarshell.end = mortarRange;
//c.transform.position = new Vector3(mortarRange.transform.position.x + a, mortarRange.transform.position.y + b, mortarRange.transform.position.z);
//_mortarshell.end.transform.position = c.transform.position;
}
}
}
์งค ์๋ณด์
๋ค์ ์ฌ๋ ธ์ด์ผ
๋ชฉํ์์น๋ฅผ ์ ํธ๋์คํผ์ผ๋ก ํ๋๊ฑฐ? Vector3๋ก๋ ์๋๋๊ฑฐ์?
ํธ๋์คํผ์ด๋ ๋ฒกํฐ3๋ ๋ณํ์ ์ด์ผ ํ๋์ง ์ ๋ชจ๋ฆ
์๋ ์น๊ตฌ ๋ง๋๋ก ๋๋ค๊ฐ ๋ํด์ฃผ๋ฉด ๋จ, Random.insideUnitCircle์ด๋ผ๊ณ ๋ฐ์ง๋ฆ 1๋งํผ์ ์ ๊ธฐ์ค ๋๋ค์ผ๋ก ์ ํ๋ ์ฐ์ด์ ๋ฆฌํดํด์ฃผ๋ ๋ฒกํฐ ์์.
๋ญ ์๋ฆฌ์ธ์ง ๋ชจ๋ฅด๊ฒ ๋ค. Transform ๋ด์ position์ด๋ผ๋ Vector3 ๊ฐ ์์๋
transform.position + Random.insideUnitCircle * (์ํ๋ ์์ ํฌ๊ธฐ)
๋ชฉํ์ง์ ์ ๋๋ค๊ฐ ๋ํด์ฃผ๋ฉด ๋์๋ ์ด๋๋ถ๋ถ์ด ๊ถ๊ธํ๊ฑฐ์?
๊ทธ๋๊น ๋ชฉํ์ง์ ์ ๋๋ค๊ฐ ๋ํด์ฃผ๋ ๋ฐฉ์์ ๋ชจ๋ฅด๊ฒ ์ ใ ใ
2์ฐจ์์ด๋ฉด Random.insideUnitCircle ์จ๋ ๋๊ณ ๋ ๊ฐ๋จํ๊ฒ Random.Range๊ฐ ๋ํด์ค๋ ๋์ง ๋ฒจํธ์คํฌ๋กค ๋ทฐ๊ฐ์ผ๋๊น x๊ฐ ์ข๋ ํธ์ฐจ ํฌ๊ฒ๋๊ณ
๊ธ๊ณ ์๋๋ง๋๋ก Transform๋ง๊ณ Vector๋ก ํ๋๊ฒ ์กฐ์๋ณด์