본문 바로가기
게임개발/게임 클라이언트 프로그래밍

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

by pudding81 2024. 1. 28.
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축으로 계속 이동
    }
}

'게임개발 > 게임 클라이언트 프로그래밍' 카테고리의 다른 글

표창 던지기  (1) 2024.01.28
SwipeCar  (0) 2024.01.28
룰렛 만들기 GetMouseButtonDown  (1) 2024.01.28
Time.deltaTime  (0) 2024.01.28
벡터 연산의 이해  (0) 2024.01.25