์บก์А ์˜ค๋ธŒ์ ํŠธ์— ๋ฉ”์ธ ์นด๋ฉ”๋ผ๊ฐ€ ๋”ฐ๋ผ๊ฐ€๊ฒŒ ํ•˜๋ฉด์„œ ํšŒ์ „๋„ ๊ฐ™์ดํ•˜๊ฒŒ ํ•ด์คฌ๋Š”๋ฐ

๊ฒŒ์ž„ ์‹คํ–‰์‹œํ‚ค๋‹ˆ๊นŒ ์นด๋ฉ”๋ผ๊ฐ€ ์œ„์•„๋ž˜๋กœ ์กด๋‚˜๊ฒŒ ํ”๋“ค๋ฆผ;;

์ด๊ฑฐ ์™œ ์ด๋Ÿฌ๋Š”์ง€์ข€ ์•Œ์ˆ˜ ์žˆ์„๊นŒ์š”....




์นด๋ฉ”๋ผ์— ๋‹ฌ์•„์ค€ ์Šคํฌ๋ฆฝํŠธ

์บ  ํšŒ์ „

===========================================

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class CamRotate : MonoBehaviour

{


ย  ย  public float rotSpeed = 200f;


ย  ย  float mx = 0;

ย  ย  float my = 0;


ย  ย  // Start is called before the first frame update

ย  ย  void Start()

ย  ย  {



ย  ย  }


ย  ย  // Update is called once per frame

ย  ย  void Update()

ย  ย  {

ย  ย  ย  ย  Cursor.lockState = CursorLockMode.Confined;


ย  ย  ย  ย  float mouse_X = Input.GetAxis("Mouse X");

ย  ย  ย  ย  float mouse_Y = Input.GetAxis("Mouse Y");


ย  ย  ย  ย  mx += mouse_X * rotSpeed * Time.deltaTime;

ย  ย  ย  ย  my += mouse_Y * rotSpeed * Time.deltaTime;

ย 

ย  ย  ย  ย  my = Mathf.Clamp(my, -90, 90);


ย  ย  ย  ย  transform.eulerAngles = new Vector3(-my, mx, 0);


ย  ย  ย  ย  my = Mathf.Clamp(my, -90, 90);


ย  ย  }

}

===================================================

์บ  ํŒ”๋กœ์šฐ
============================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CamFollow : MonoBehaviour
{

ย  ย  public Transform target;
ย  ย  // Start is called before the first frame update
ย  ย  void Start()
ย  ย  {

ย  ย  }

ย  ย  // Update is called once per frame
ย  ย  void Update()
ย  ย  {

ย  ย  ย  ย  transform.position = target.position;
ย  ย  }
}
===============================================


์˜ค๋ธŒ์ ํŠธ์— ๋ถ™์ธ ์Šคํฌ๋ฆฝํŠธ

์ด๋™
==============================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Move : MonoBehaviour
{
ย  ย  public float moveSpeed = 7f; // ์บ๋ฆญํ„ฐ์˜ ์ด๋™ ์†๋„
ย  ย  CharacterController cc; // ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ
ย  ย  float gravity = -20f; // ์ค‘๋ ฅ์˜ ๊ฐ’
ย  ย  float yVelocity = 0; // ์ˆ˜์ง ๋ฐฉํ–ฅ์˜ ์†๋„
ย  ย  public float jumpPower = 7f; // ์ ํ”„์˜ ํž˜
ย  ย  public bool isJumping = false; // ์ ํ”„ ์ค‘์ธ์ง€ ํŒ๋‹จํ•˜๋Š” ๋ณ€์ˆ˜

ย  ย  void Start()
ย  ย  {
ย  ย  ย  ย  cc = GetComponent<CharacterController>(); // ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ ธ์˜ด
ย  ย  }

ย  ย  void Update()
ย  ย  {
ย  ย  ย  ย  float h = Input.GetAxis("Horizontal"); // ์ˆ˜ํ‰ ์ž…๋ ฅ์„ ๋ฐ›์Œ
ย  ย  ย  ย  float v = Input.GetAxis("Vertical"); // ์ˆ˜์ง ์ž…๋ ฅ์„ ๋ฐ›์Œ

ย  ย  ย  ย  Vector3 dir = new Vector3(h, 0, v); // ์ด๋™ ๋ฐฉํ–ฅ์„ ์„ค์ •
ย  ย  ย  ย  dir = dir.normalized; // ๋ฐฉํ–ฅ์˜ ๊ธธ์ด๋ฅผ 1๋กœ ๋งŒ๋“ฆ
ย  ย  ย  ย  dir = Camera.main.transform.TransformDirection(dir); // ์นด๋ฉ”๋ผ์˜ ๋ฐฉํ–ฅ์œผ๋กœ ๋ณ€ํ™˜

ย  ย  ย  ย  if (cc.collisionFlags == CollisionFlags.Below && isJumping) // ์บ๋ฆญํ„ฐ๊ฐ€ ๋ฐ”๋‹ฅ์— ์žˆ๊ณ , ์ ํ”„ ์ค‘์ด๋ผ๋ฉด
ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  isJumping = false; // ์ ํ”„ ์ƒํƒœ๋ฅผ ๋๋ƒ„
ย  ย  ย  ย  ย  ย  yVelocity = 0; // ์ˆ˜์ง ์†๋„๋ฅผ 0์œผ๋กœ ์ดˆ๊ธฐํ™”
ย  ย  ย  ย  }

ย  ย  ย  ย  if (Input.GetButtonDown("Jump") && !isJumping) // ์ ํ”„ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €๊ณ , ์ ํ”„ ์ค‘์ด ์•„๋‹ˆ๋ผ๋ฉด
ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  yVelocity = jumpPower; // ์ ํ”„ ํž˜์„ ์ˆ˜์ง ์†๋„์— ์ถ”๊ฐ€
ย  ย  ย  ย  ย  ย  isJumping = true; // ์ ํ”„ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ
ย  ย  ย  ย  }

ย  ย  ย  ย  yVelocity += gravity * Time.deltaTime; // ์ค‘๋ ฅ์˜ ์˜ํ–ฅ์„ ์ˆ˜์ง ์†๋„์— ์ถ”๊ฐ€
ย  ย  ย  ย  dir.y = yVelocity; // ์ด๋™ ๋ฐฉํ–ฅ์˜ y ๊ฐ’์— ์ˆ˜์ง ์†๋„๋ฅผ ์ ์šฉ

ย  ย  ย  ย  cc.Move(dir * moveSpeed * Time.deltaTime); // ์ด๋™ ๋ฐฉํ–ฅ์œผ๋กœ ์ด๋™
ย  ย  }
}
===================================================

ํšŒ์ „
=====================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rotate : MonoBehaviour
{
ย  ย  public float rotSpeed = 200f;
ย  ย  float mx = 0;
ย  ย  // Start is called before the first frame update
ย  ย  void Start()
ย  ย  {

ย  ย  }

ย  ย  // Update is called once per frame
ย  ย  void Update()
ย  ย  {
ย  ย  ย  ย  float mouse_x = Input.GetAxis("Mouse X");
ย  ย  ย  ย  mx += mouse_x * rotSpeed * Time.deltaTime;
ย  ย  ย  ย  transform.eulerAngles = new Vector3(0, mx, 0);
ย  ย  }
}
===================================================