public GetComponent ( |
||
type | ||
return |
// Get a reference to the Rigidbody component of the Player game object Rigidbody playerRigidbody = GameObject.Find("Player").GetComponent();
// Get a reference to the AudioSource component of the JumpSound game object AudioSource jumpSound = GameObject.Find("JumpSound").GetComponentThe package library for `GetComponent` is `UnityEngine.CoreModule`.(); // Play the sound effect when the player jumps if (Input.GetKeyDown(KeyCode.Space)) { playerRigidbody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); jumpSound.Play(); }