using System.Collections;
using System.Collections.Generic;
using UnityEngine;
struct MyVector
{
public float x;
public float y;
public float z;
public float magnitude { get { return Mathf.Sqrt(x * x + y * y + z * z); } }
public MyVector normalized { get { return new MyVector(x/magnitude,y/magnitude, z/magnitude); } }
public MyVector(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
public static MyVector operator + (MyVector a, MyVector b)
{
return new MyVector(a.x+ b.x,a.y + b.y,a.z+ b.z);
}
public static MyVector operator -(MyVector a, MyVector b)
{
return new MyVector(a.x - b.x, a.y - b.y, a.z - b.z);
}
public static MyVector operator *(MyVector a, float d)
{
return new MyVector(a.x - d, a.y - d, a.z - d);
}
}
public class PlayerController : MonoBehaviour
{
public float _speed = 10.0f;
void Start()
{
MyVector to = new MyVector(10.0f, 0.0f, 0.0f);
MyVector from = new MyVector(5.0f, 0.0f, 0.0f);
MyVector dir = from - to;//(-5.0f, 0.0f, 0.0f);
dir = dir.normalized;
MyVector newPos = from + dir * _speed;
}
//GameObject (Player)
//Transform
//PlayerController(*)
void Update()
{
//Local -> World
//TransformDirection
//World -> Local
//InverseTransformdirection
if (Input.GetKey(KeyCode.W))
transform.Translate(Vector3.forward * Time.deltaTime);
if (Input.GetKey(KeyCode.S))
transform.Translate(Vector3.back * Time.deltaTime);
if (Input.GetKey(KeyCode.D))
transform.Translate(Vector3.right * Time.deltaTime);
if (Input.GetKey(KeyCode.A))
transform.Translate(Vector3.left * Time.deltaTime);
//transform
}
}
'UnityTechnique' 카테고리의 다른 글
유니티 기기 사용하지 않고 디바이스 에뮬레이터 사용 방법 (0) | 2024.08.03 |
---|---|
VR 기기 없이 유니티 연동하기 (0) | 2024.07.29 |
유니티 내부 NotificationSettings 사용방법 (1) | 2024.07.24 |
Singleton 패턴 (0) | 2023.07.26 |
코르틴(Coroutine)이란 (0) | 2023.06.28 |