User Tools

Site Tools


notes:unity3d:engine

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
notes:unity3d:engine [2020/01/15]
leszek
notes:unity3d:engine [2020/01/16] (current)
leszek
Line 2: Line 2:
  
 ===== Fundamentals ===== ===== Fundamentals =====
 +
 +The **Hierarchy** view organizes elements using GameObjects. Empty GameObjects serve as containers for other GameObjects.
 +
 +{{HierarchyView.png}}
 +
 +The **Project** view organizes elements using folders:
 +
 +{{ProjectView.png}}
  
 Add a 3D GameObject (a plane) to the scene (two methods): Add a 3D GameObject (a plane) to the scene (two methods):
Line 12: Line 20:
 Reset the GameObject'​s Transform using the context-sensitive Gear menu of the Transform component: Reset the GameObject'​s Transform using the context-sensitive Gear menu of the Transform component:
  
-{{ transformreset.png }}+{{TransformReset.png}}
  
 Rename the GameObject (two ways): Rename the GameObject (two ways):
Line 24: Line 32:
   * Select the object in the Hierarchy view > Menu: Edit > Frame Selected   * Select the object in the Hierarchy view > Menu: Edit > Frame Selected
  
-Scale the GameObject:+Scale the GameObject ​(two ways):
  
   * {{ScaleTool.png}} drag the red, green, or blue handles in the Scene view   * {{ScaleTool.png}} drag the red, green, or blue handles in the Scene view
   * {{TransformScale.png}} type the values or drag the X, Y, or Z labels   * {{TransformScale.png}} type the values or drag the X, Y, or Z labels
 +
 +Duplicate the GameObject (two ways):
 +
 +  * Select the object in the Hierarchy view > Menu: Edit > Duplicate
 +  * Select the object in the Hierarchy view > Ctrl + D
 +
 +Activate and deactivate the GameObject by clicking the Active checkbox. When the object is deactivated,​ it is not visible in the scene:
 +
 +{{GameObjectActiveCheckbox.png}}
  
 Use a **material** to add a color or a texture to an object: Use a **material** to add a color or a texture to an object:
Line 35: Line 52:
 Change the material'​s color: Change the material'​s color:
  
-{{ MaterialAlbedo.png }}+{{MaterialAlbedo.png}}
  
 Apply the material to the object by dragging the material from the Project view onto the object in the Scene view. Apply the material to the object by dragging the material from the Project view onto the object in the Scene view.
Line 43: Line 60:
   * Menu: Component > Physics > Rigidbody   * Menu: Component > Physics > Rigidbody
   * Inspector: [Add Component] > Physics > Rigidbody   * Inspector: [Add Component] > Physics > Rigidbody
 +
 +Set the position of the **camera** by lifting it up by 10 units and tilting it down by 45 degrees:
 +
 +| {{CameraPositionTransform.png?​280}} | {{CameraPositionView.png?​400}} |
 +
 +A **prefab** is a blueprint for a GameObject or a GameObject family. A **prefab instance** is a copy of a prefab placed in a scene.
 +
 +  * Create a prefab by dragging a GameObject from the Hierarchy view and dropping it in the Project view.
 +  * Apply a material to the prefab by dropping the material on the prefab in the Project view.
 +
 +Switch between Global and Local modes:
 +
 +{{LocalGlobalMode.png}}
 +
 +  * Use Global mode when you want to position an object relative to the scene coordinate system. ​
 +  * Use Local mode when you want to position an object relative to its local coordinate system.
  
 Create a C# script (three ways): Create a C# script (three ways):
Line 56: Line 89:
   * Context-sensitive gear menu > Edit Script   * Context-sensitive gear menu > Edit Script
  
-{{ ScriptEdit.png }}+{{ScriptEdit.png}}
  
 The PlayerController script allows the player to move the GameObject using the keyboard: The PlayerController script allows the player to move the GameObject using the keyboard:
Line 94: Line 127:
         // with the Rigidbody will start moving. ​         // with the Rigidbody will start moving. ​
         rb.AddForce(movement * speed);         rb.AddForce(movement * speed);
 +    }
 +}
 +</​code>​
 +
 +Make the camera follow the player GameObject by attaching the CameraConroller script to the camera:
 +
 +{{CameraFollowingPlayer.png}}
 +
 +<code csharp>
 +using UnityEngine;​
 +
 +public class CameraConroller : MonoBehaviour
 +{
 +    // The player object. It needs to be provided in the camera'​s Inspector view.
 +    public GameObject player;
 +
 +    // A difference between the current position of the camera and the position of the player.
 +    private Vector3 offset;
 +
 +    void Start ()
 +    {
 +        // Calculate the offset by subtracting the position of the player from the position of the camera.
 +        // The offset is constant.
 +        offset = transform.position - player.transform.position;​
 +    }
 +
 +    // LateUpdate is used to update the follow cameras, procedural animations, and to gather last known state.
 +    // LateUpdate is guaranteed to be called after all items in the frame are processed.
 +    void LateUpdate ()
 +    {
 +        // Move the camera to a position aligned with the player object. ​
 +        // We execute this code in LateUpdate because we know that the player ​
 +        // has already moved.
 +        transform.position = player.transform.position + offset;
 +    }
 +}
 +</​code>​
 +
 +Rotate a GameObject:
 +
 +<code csharp>
 +using UnityEngine;​
 +
 +public class Rotator : MonoBehaviour
 +{
 +    // Update is called once per frame. We can use Update instead of FixedUpdate
 +    // because we are not using forces in this script.
 +    void Update()
 +    {
 +        // Multiply the rotation angles by Time.deltaTime to make the rotation smooth and frame rate independent.
 +        transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);​
     }     }
 } }
Line 102: Line 186:
 Show or hide the grid from the Gizmos menu in the upper-right corner of the Scene view: Show or hide the grid from the Gizmos menu in the upper-right corner of the Scene view:
  
-{{ GizmosMenu.png }}+{{GizmosMenu.png}}
  
 +Move the Scene view to the top-down view by clicking Y in the gizmo:
 +
 +{{GizmoTopDownView.png}}
  
 ====== 2D ====== ====== 2D ======
 +
 +====== Links ======
 +
 +  * [[https://​unity3d.com/​learn/​tutorials/​topics/​graphics/​cameras|Cameras Overview]]
 +
  
  
  
  
notes/unity3d/engine.1579146186.txt.gz ยท Last modified: 2020/01/15 by leszek