BallGame
유니티 튜토리얼에 비슷한 게임이 있지만, 거기서 한단계 업그레이드 되어 만든 게임.
Vector3(0, 0, 0) // x축, y축, z축
ex) float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
rigid.AddForce(new Vector3(h, 0, v), ForceMode.Impulse);
Input.GetAxis("Horizontal"); //Left, Right를 눌렀을때 -1.0f~1.0f까지의 값을 반환한다.
Input.GetAxis("Vertical"); //Up, Down을 눌렀을때 -1.0f~1.0f까지의 값을 반환한다.
ex) public float jumpPower = 30;
ex) transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime, Space.World);
Transform playerTransform;
Vector3 offset;
void Start()
{
//따라다닐 물체의 Tag이름
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
offset = transform.position - playerTransform.position;
}
void LateUpdate()
{
//offset 해줘야 벡터 일정거리 유지하면서 따라다님
transform.position = playerTransform.position + offset;
}
//스크립트가 달린 물체(A)가 다른 콜라이더를 가진 태그된 물체(B)와 "닿았을 때"를 의미합니다.
private void OnCollisionEnter(Collision collision){}
//Trigger은 물리적 연산을 하지않고 충돌을 감지한다.
//TriggerEnter로 할 경우 Inspector에서 Is Trigger 체크해줘야 한다.
//Is Trigger를 하지않으면 물체가 통과된다,
void OnTriggerEnter(Collider other)
{ //충돌할 Item tag명
if (other.tag == "Item")
{
//닿으면 삭제
other.gameObject.SetActive(false);
}
}