Getting Started with Unity for Begginer

2.6K Views

August 21, 22

スライド概要

profile-image

可視化技術や人間計測/空間計測技術を活用した問題解決に関する研究開発。 ARコンテンツ作成勉強会(AR_Fukuoka)を主催。

シェア

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

Getting Started with Unity

2.

Follow Me Name︓Takashi Yoshinaga Twitter︓@Tks_Yoshinaga @Taka_Yoshinaga LinkedIn︓ https://www.linkedin.com /in /tks-yoshinaga /

3.

Goal Of the Tutorial https://youtu.be/zD0A1vdmQM8

4.

Launch Unity Hub Unity Hub

5.

Create Project (1/6) ①Projects ②New Project

6.

Create Project (2/6) Click here

7.

Create Project (3/6) 2021.3.X

8.

Create Project (4/6) 3D

9.

Create Project (5/6) Project name (e.g., AR_Test) Create Project

10.

Create Project (6/6) Unity Editor is launched.

11.

Overview of Unity Editor Scene Object List Placing objects to design virtual environment List of folders and files in the project

12.

Add Object With nothing selected Right-click on a blank space in the Hierarchy

13.

Add Object ①3D Object ②Cube

14.

Add Object Cube is addec

15.

Add Object Let's check the view from the camera.

16.

Play Play

17.

Play Displayed from the camera's point of view

18.

Stop Click Play button again to stop

19.

注意︕︕ You can edit in Unity while it is running, but if you stop running, all edits will be discarded. Always stop execution before returning to editing!

20.

Next Step Change the position, angle, and size of objects!

21.

Edit Position/Angle/Size of Object① Cube

22.

Edit Position/Angle/Size of Object① Select a mode Move Rotate Scale

23.

Change the viewpoint of the Scene [←][→]: Move Right/Left [↑][↓]: Move Forward/Back Alt/option + Drag: Rotate

24.

Edit Position/Angle/Size of Object② Cube

25.

Edit Position/Angle/Size of Object② Inspector (≒Property of a object)

26.

Edit Position/Angle/Size of Object② Set params as below Position 0 5 0 Rogation 0 0 0 Scale 1 1 1

27.

Edit Position/Angle/Size of Object② Cube may not be visible in some view settings.

28.

Edit Position/Angle/Size of Object② Double Click Cube

29.

Edit Position/Angle/Size of Object② Cube will be shown at the center of scene pane

30.

Edit Position/Angle/Size of Object② Press the [↓] key to observe from a slightly distant viewpoint

31.

Edit Position/Angle/Size of Object② Easier to see the positional relationship between the camera and the object.

32.

Next Step Let's change the color of an object!

33.

⾊の設定について Cube

34.

About Color Settings Inspector See Mesh Renderer

35.

About Color Settings Open Materials Default-Material assigned with default color already set *Unity uses materials to set colors and textures.

36.

About Color Settings Material details can be viewed at the bottom of Inspector, but DefaultMaterial is not editable.

37.

Next Step Let's create editable materials!

38.

Creating Materials Project Assets

39.

Creating Materials Right Click

40.

Creating Materials ①Create ②Material

41.

Creating Materials New Material is created

42.

Applying Material Click Cube

43.

Applying Material MeshRenderer See Default-Material assigned to Materials

44.

Applying Material Drag & drop over Default-Material See New Material (do not click)

45.

Applying Material New Material Click ▷ to see details

46.

Applying Material Click □ at the right of Albedo

47.

Applying Material Select a color as you like (Close the window after color selection)

48.

Next Step Let's add new details about an object e.g.: Apply physical laws

49.

Applying Physical Law Cube Add Component

50.

Applying Physical Law Adding new component allows you to add details that are not set by default

51.

Applying Physical Law Physics

52.

Applying Physical Law Rigidbody

53.

Applying Physical Law Rigidbody is added If Use Gravity is checked, it will be affected by gravity.

54.

Play Play

55.

Applying Physical Law Cube will fall

56.

Stop Click Play again to stop

57.

Next Step Interaction between objects

58.

Adding Object to the Scene Right Click inside Hierarchy

59.

Adding Object to the Scene 3D Object Plane

60.

Adding Object to the Scene Plane is added

61.

Adding Object to the Scene Plane

62.

Adding Object to the Scene Set Position as 0 0 0

63.

Adding Object to the Scene Select Rotate Mode

64.

Adding Object to the Scene Tilt slightly toward the camera.

65.

Play Cube rolls down

66.

Next Step Realize user interactions with C# script! e.g.: Screen click/tap

67.

Mouse Click/Screen Tap Detection Right Click inside Hierarchy

68.

Mouse Click/Screen Tap Detection Create Empty

69.

Mouse Click/Screen Tap Detection Rename to ClickObject *Any name is acceptable.

70.

Mouse Click/Screen Tap Detection Add Component

71.

Mouse Click/Screen Tap Detection Clear text box New script

72.

Mouse Click/Screen Tap Detection Change Script name to ClickScript *Any name is acceptable. Create and Add

73.

Mouse Click/Screen Tap Detection ClickScript is added

74.

Mouse Click/Screen Tap Detection Assets Double click to open ClickScript

75.

Mouse Click/Screen Tap Detection public class ClickScript : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } }

76.

Mouse Click/Screen Tap Detection // Start is called before the first frame update void Start() { } // Update is called once per frame Check for mouse void Update() click every frame { if (Input.GetMouseButtonDown(0)) { Debug.Log("Click!"); } }

77.

Ctrl/Command + S To Save Script

78.

Mouse Click/Screen Tap Detection Console

79.

Play Playボタン

80.

Mouse Click/Screen Tap Detection Click Screen Results are shown

81.

Stop Click Play again to stop

82.

Next Step Let's generate objects dynamically! e.g.: Throwing a Cube by clicking on the screen

83.

Generate Box Dynamically Cube placed in Hierarchy already exists in space → Instead, I want to make it appear in space when the screen is clicked

84.

Generate Box Dynamically Project

85.

Generate Box Dynamically Cube

86.

Generate Box Dynamically Drag & Drop Cube into Assets Folder Assets

87.

Generate Box Dynamically A file with information about Cube with physics applied is created

88.

Generate Box Dynamically Make a Cube appear in space from a script using data described in a file

89.

Generate Box Dynamically // Link variables with Cube file [SerializeField] GameObject cube; void Start() { } // 毎フレーム実⾏される void Update() { if (Input.GetMouseButtonDown(0)) { Debug.Log("Click!"); } }

90.
[beta]
Generate Box Dynamically
// 毎フレーム実⾏される
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Click!");
//Generate box in the scene
GameObject obj = GameObject.Instantiate(cube);
//Acquire main camera to use its position
Camera cam = Camera.main;
//Set camera position as default position of the cube
obj.transform.position = cam.transform.position;
//Add force to shoot cube from camera
obj.GetComponent<Rigidbody>().AddForce(
10 * cam.transform.forward, ForceMode.Impulse);
}
}

91.

Ctrl/Command + S To Save the Script

92.

Generate Box Dynamically ClickObject

93.

Generate Box Dynamically Drag & Drop Cube File into the right box of Cube variable Cube File

94.

Play Play

95.

Play Cube can be shoot form camera

96.

Stop Click Play again to stop

97.

Next Step Let's realize delayed processing! e.g.: Delete Cube after 10 seconds

98.

Automatic Deletion of Cube Cube

99.

Automatic Deletion of Cube Add Component

100.

Automatic Deletion of Cube New script

101.

Automatic Deletion of Cube Set script name as AutoDestroy Create and Add

102.

Automatic Deletion of Cube AutoDestroy is added

103.

Automatic Deletion of Cube Double Click AutoDestroy to edit

104.

Cube Destroy Coroutine public class AutoDestroy : MonoBehaviour { void Start() { StartCoroutine(DestroyWithDelay()); } IEnumerator DestroyWithDelay() { // Erase itself after 10 seconds yield return new WaitForSeconds(10); Destroy(gameObject); } } void Update() { }

105.

Ctrl/Command + S To Save the Script

106.

Play Play Button

107.

Play Cube disappears after a certain time.

108.

Stop Click Play again to stop

109.

Complete!