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/09/16 20:38] – [Attaching a C# Script to a GameObject] yann | brasil:courses:blender_unity:unity:4_moving_objects [2026/09/17 20:16] (Version actuelle) – [Exercise] yann | ||
|---|---|---|---|
| Ligne 250: | Ligne 250: | ||
| {{: | {{: | ||
| - | {{ : | + | {{ : |
| + | |||
| + | <code csharp | turnAround.cs> | ||
| + | |||
| + | using UnityEngine; | ||
| + | |||
| + | public class TurnAround : MonoBehaviour | ||
| + | { | ||
| + | // Drag & drop the player in the inspector | ||
| + | // public Transform Target; | ||
| + | public GameObject Target; | ||
| + | public float RotationSpeed = 1; | ||
| + | public float CircleRadius = 1; | ||
| + | public float ElevationOffset = 0; | ||
| + | |||
| + | private Vector3 positionOffset; | ||
| + | private float angle; | ||
| + | //private Transform TargetT; | ||
| + | |||
| + | // Start is called before the first frame update | ||
| + | void Start() | ||
| + | { | ||
| + | //TargetT = Target.transform; | ||
| + | } | ||
| + | |||
| + | |||
| + | void Update() | ||
| + | { | ||
| + | positionOffset.Set(Mathf.Cos(angle) * CircleRadius, | ||
| + | transform.position = Target.transform.position + positionOffset; | ||
| + | angle += Time.deltaTime * RotationSpeed; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | <code csharp | lookAt.cs> | ||
| + | using UnityEngine; | ||
| + | |||
| + | public class LookAt : MonoBehaviour | ||
| + | { | ||
| + | public Transform target; | ||
| + | // Start is called before the first frame update | ||
| + | void Start() | ||
| + | { | ||
| + | |||
| + | } | ||
| + | |||
| + | // Update is called once per frame | ||
| + | void Update() | ||
| + | { | ||
| + | // Rotate the camera every frame so it keeps looking at the target | ||
| + | transform.LookAt(target); | ||
| + | |||
| + | // Same as above, but setting the worldUp parameter to Vector3.left in this example turns the camera on its side | ||
| + | // | ||
| + | } | ||
| + | } | ||
| + | </ | ||
