Transform 컴포넌트 위치에 Vector3(x좌표, y좌표, z좌표)를 입력하면 이동시킬 수 있다.


Random 위치는 Random.Range(시작, 끝) Random한 값을 가져올 범위를 입력해주면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class EnemyControl : MonoBehaviour
{
    public float Speed = 50.0f;
    private Transform myTransform = null;
    
    // Start is called before the first frame update
    void Start()
    {
        myTransform = GetComponent<Transform>();
    }
 
    // Update is called once per frame
    void Update()
    {
        Vector3 moveAmount = Speed * Vector3.back * Time.deltaTime;
        myTransform.Translate(moveAmount);
 
        if(myTransform.position.y <= -60.0f)
        {
            myTransform.position = new Vector3(Random.Range(-60.0f, 60.0f), 60.0f, 0.0f);
        }
    }
}
cs


'유니티' 카테고리의 다른 글

[유니티] 폭발 이펙트 추가  (0) 2019.03.12
[유니티] Object 충돌  (0) 2019.03.08
[유니티] Object 생성  (0) 2019.03.05
[유니티]Object 삭제  (0) 2019.03.04
[유니티] Object 좌우 이동  (0) 2019.03.02

+ Recent posts