// prg6-1 角色空白鍵跳躍 using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { // Start is called before the first frame update Rigidbody2D rigid2D; float jumpForce = 680.0f; void Start() { this.rigid2D = GetComponent(); //Rigidbody2D rigid2D = this.gameObject.GetComponent(); } // Update is called once per frame void Update() { // Jump if(Input.GetKeyDown(KeyCode.Space)) { this.rigid2D.AddForce(transform.up * this.jumpForce); } } }