-
[Prototype3] 점프 및 중력(Physics.gravity)카테고리 없음 2022. 5. 16. 09:22
Physics.gravity
public static Vector3 gravity;
씬의 모든 리지드바디(rigidbody)에 적용되는 중력을 나타냄
예제)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Example : MonoBehaviour { void Exam() { Physics.gravity = new Vector3(0, -1.0f, 0); } }
본문)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { private Rigidbody playerRb; public float jumpForce; public float gravityModifier; void Start() { playerRb = GetComponent<Rigidbody>(); Physics.gravity *= gravityModifier; } void Update() { if (Input.GetKeyDown(KeyCode.Space)) { playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); } } }