Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| brasil:courses:blender_unity:unity:4_moving_objects [2026/08/25 18:56] – [Attaching a C# Script to a GameObject] yann | brasil:courses:blender_unity:unity:4_moving_objects [2026/08/25 19:29] (Version actuelle) – [Exercise] yann | ||
|---|---|---|---|
| Ligne 95: | Ligne 95: | ||
| { | { | ||
| // if the spacebar is pressed | // if the spacebar is pressed | ||
| - | if (Input.GetKeyDown(" | + | |
| + | if(UnityEngine.InputSystem.Keyboard.current.spaceKey.wasPressedThisFrame) | ||
| { | { | ||
| // log a message to the console | // log a message to the console | ||
| Ligne 119: | Ligne 120: | ||
| To test our code, we're going to run our game in the editor: | To test our code, we're going to run our game in the editor: | ||
| - | {{: | + | {{ : |
| If you press the spacebar, you'll notice that the Earth disappears (it is no longer displayed by the render engine because its GameObject' | If you press the spacebar, you'll notice that the Earth disappears (it is no longer displayed by the render engine because its GameObject' | ||
| Ligne 125: | Ligne 126: | ||
| Stay in Play mode (with the Game tab active), select the Earth GameObject in the hierarchy on the left if you haven’t already, and check the status of the GameObject’s visibility checkbox in the Inspector on the right. | Stay in Play mode (with the Game tab active), select the Earth GameObject in the hierarchy on the left if you haven’t already, and check the status of the GameObject’s visibility checkbox in the Inspector on the right. | ||
| - | {{: | + | {{ : |
| + | {{ : | ||
| The interface reflects the changes made by the running code when you are in Play mode. This provides a basic level of visual debugging within the editor. | The interface reflects the changes made by the running code when you are in Play mode. This provides a basic level of visual debugging within the editor. | ||
| Ligne 133: | Ligne 135: | ||
| Debug.Log statements write a log to the editor console. These logs are a starting point for debugging; they let you know which lines of code have been executed and even display the values of variables. | Debug.Log statements write a log to the editor console. These logs are a starting point for debugging; they let you know which lines of code have been executed and even display the values of variables. | ||
| - | {{: | + | {{ : |
| ===== The Earth rotates... ===== | ===== The Earth rotates... ===== | ||
| Ligne 144: | Ligne 146: | ||
| using UnityEngine; | using UnityEngine; | ||
| - | public class EarthRotation | + | public class earthRotate |
| { | { | ||
| public Vector3 localRotationSpeed; | public Vector3 localRotationSpeed; | ||
| - | // Start is called before the first frame update | + | // Start is called |
| - | | + | void Start() |
| { | { | ||
| + | | ||
| } | } | ||
| // Update is called once per frame | // Update is called once per frame | ||
| - | | + | void Update() |
| { | { | ||
| this.transform.Rotate(localRotationSpeed * Time.deltaTime, | this.transform.Rotate(localRotationSpeed * Time.deltaTime, | ||
| Ligne 166: | Ligne 168: | ||
| Set the Y-axis to 50. | Set the Y-axis to 50. | ||
| - | {{: | + | {{ : |
| This variable is of type Vector3, meaning it’s a 3-dimensional vector that can store a value for the X axis, a value for the Y axis, and a value for the Z axis. | This variable is of type Vector3, meaning it’s a 3-dimensional vector that can store a value for the X axis, a value for the Y axis, and a value for the Z axis. | ||
| Ligne 175: | Ligne 177: | ||
| In the editor, you can see in real time that your script is changing the GameObject’s rotation along the Y-axis. | In the editor, you can see in real time that your script is changing the GameObject’s rotation along the Y-axis. | ||
| - | {{: | + | {{ : |
| ===== Conclusion ===== | ===== Conclusion ===== | ||
| Ligne 183: | Ligne 185: | ||
| ===== Exercise ===== | ===== Exercise ===== | ||
| - | - Add a Milky Way skybox; to do this, use the Asset Store (Milky Way Skybox) | + | - Add a Milky Way skybox; to do this, use the Asset Store (Milky Way Skybox) |
| - Make the moon rotate on its axis | - Make the moon rotate on its axis | ||
| - Make the moon orbit the Earth | - Make the moon orbit the Earth | ||
