Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
brasil:courses:blender_unity:unity:4_moving_objects [2026/09/16 20:34] – [Attaching a C# Script to a GameObject] yannbrasil:courses:blender_unity:unity:4_moving_objects [2026/09/17 20:16] (Version actuelle) – [Exercise] yann
Ligne 164: Ligne 164:
             // `activeSelf` indicates the GameObject's visibility             // `activeSelf` indicates the GameObject's visibility
             // can't deactivate and reactivate the parent directly -> scripts are disabled when object is inactive             // can't deactivate and reactivate the parent directly -> scripts are disabled when object is inactive
-            //gets all the direct children from the parent through "Transform" property, because every object has a transform property+            // gets all the direct children from the parent through "Transform" property, because every object has a transform property
             foreach (Transform child in this.transform)              foreach (Transform child in this.transform) 
                 {                 {
Ligne 250: Ligne 250:
 {{:brasil:courses:blender_unity:unity:earthandmoon.png?1024|}} {{:brasil:courses:blender_unity:unity:earthandmoon.png?1024|}}
  
-{{ :brasil:courses:blender_unity:unity:earthturning.mp4 |}}+{{ :brasil:courses:blender_unity:unity:earthandmoonrotating.mp4 |}} 
 + 
 +<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, ElevationOffset, Mathf.Sin(angle) * CircleRadius); 
 +        transform.position = Target.transform.position + positionOffset; 
 +        angle += Time.deltaTime * RotationSpeed; 
 +    } 
 + 
 + } 
 +</code> 
 + 
 +<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 
 +        //transform.LookAt(target, Vector3.left); 
 +    } 
 +} 
 +</code>
brasil/courses/blender_unity/unity/4_moving_objects.1789583675.txt.gz · Dernière modification : de yann
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0