게임개발/게임 클라이언트 프로그래밍

벡터의 연산 : 게임오브젝트 이동

pudding81 2024. 1. 28. 12:24
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class App : MonoBehaviour
{
    [SerializeField]
    private GameObject playerGo;    //게임오브젝트 변수 xxxGo

    private void Start()
    {
        Vector2 playerPos = new Vector2(3.0f, 4.0f);
        
        playerGo.transform.position = playerPos; // 오브젝트 이동 3, 4, 0
            
        playerPos.x += 8.0f;
        playerPos.y += 5.0f;
     
        playerGo.transform.position = playerPos;   //11, 9, 0   
      
  
    }
}


------------------------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class App : MonoBehaviour
{
    [SerializeField]
    private GameObject playerGo; 

    private void Start()
    {
    }
    
    //매 프레임마다 호출됨 
    private void Update()
    {
        Vector3 pos = new Vector3(0.001f, 0, 0);  
        playerGo.transform.position += pos; //x축으로 계속 이동
    }
}