Four Windows (Scene, Project, Hierarchy, Inspector), Customizable Layout

Total Page:16

File Type:pdf, Size:1020Kb

Four Windows (Scene, Project, Hierarchy, Inspector), Customizable Layout

July, 2017 Hayashi UNITY WORKSHOP

■ Unity Editor

 Project : Name your project. A folder is created with the same name of the project. Everything is in the folder.  Four windows (Scene, Project, Hierarchy, Inspector), customizable layout.  Everything is managed by "Object" (GameObject).  Let's create "Object": Create "Cube" (right click on Hierarchy pane)  View operation: FirstPersonShooter、WASD key、F key、AroundObject、Gizmo (xyz- coordinate, etc.)  Operate "Object": Translate、Rotation、Scale  Basic operation is: To attach "Component" to an "Object" then to operate the Component on Inspector pane.  Camera view: Setup a camera  Lighting: Directional light、Point light、Shadow、Skybox etc.  Let's run the program (scene): Be aware of Scene mode/Game mode  Save scene: Scene change available (level design)

■ Programming(Unity Script)

 Let's add a C# script to "Asset", then open it with "Mono develop" (or Visual Studio). Start() and Update() functions.  File name has to coincide with Class name (otherwise error)  Let's move the object by giving: transform.position = new Vector3(Mathf.Sin (Time.time), 2, 0);  Attach the script to an object then play it  Try getting errors in a code.  Debug (simplest): Display variables by "Debug.Log( xxx );"  Let's rotate the object: transform.rotation = Quaternion.AngleAxis(Time.time , new Vector3(0,0,1));  Let's scale the object: transform.localScale = new Vector3(Mathf.Sin (Time.time), 1, 1);  Save the scene, build, then Run.

■ Basic function

 Physics: Attach "RigidBody" component to an object.  Try dropping it. Try adding a sphere and slant the floor to see the ball rolling out.  Hierarchy structure (Parenting) : Make a "kokeshi" with a ball and a cube. Create an empty object and drag the ball and the cube. Then add RigidBody to the parent object.  Prefab: Create a prefab of the "kokeshi". Just drag the "kokeshi" in the Hierarchy pane and drop onto the Project pane.  Instantiate a prefab: Just drag the prefab in the Project pane onto the Hierarchy pane. Let's create many instantiated objects then drop them all.  Physic material : Right click on the Project pane to make a "Physic material" then drag it to a "Collider" component. Same as doing to the floor also. Check out how the object moves by adjusting "Bounce" and "Friction".  Instantiate a prefab by Unity Script : public GameObject ballPrefab; // Drag the prefab to the " ballPrefab " in advance GameObject ball = (GameObject)Instantiate(ballPrefab, transform.position, Quaternion.identity);  Give velocity to the ball: ball.GetComponent().velocity = transform.up * 10.0f;

■ Input and GUI

// Keyboard, Mouse, Joystick, etc. void Update () { if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("HIT!"); } }

// Button, Label, Checkbox, Text input, Slider, etc. void OnGUI () { if( GUI.Button(new Rect(10, 10, 100, 20), "PUSH") ) { Debug.Log("PRESSED"); } }

■ Appearance

 Material : Create in the project pane (right click on "Assets" pane). Coloring and Texturing, etc.  Texture: Drag an image file on the Assets pane then set it to "Albedo" in the material.  Import model: Asset Store: Download then use it. Easiest way. Free or Pay. Primitives: Assemble the primitives in the UnityEditor. DIY: Model your object by appropriate modeling tool such as Maya, Blender, etc. Export the model as a FBX or 3ds(or other) file then drag it to the Assets for importing.  Add sound: Drag your sound files to the Assets and play it back. It needs an AudioSource component and an AudioListener component.  Customize your buttons and texts: Use "GUIStyle": e.g. GUI.Label(Rect position, string text, GUIStyle style);  You can drag and drop font files to import.  You can store your player preferences by using "PlayerPrefs".  Finally build it to make the executable. You can build it for any platform such as Windows, MAC, Linux, iOS, Android etc. simply by changing the "Build platforms". You can change the platform by "Switch platform" in the BuildSettings. You may need to install necessary modules for the build. Most of them are free.  Check out "Edit~ProjectSettings~PlayerSettings" when building.

■ Trouble shooting

 Google it.  Retrieve the similar question in the community "Unity Answer".  Ask by yourself in "Unity Answer" (English)  Join "Unity ユーザー助け合い所" of Facebook and ask in Japanese.  Ask your friend.  Ask your teacher.

■ Workout:"Bowling game"

 Create a floor, a pin and a ball by Primitives then attach RigidBody to the pin and the ball, then add Physic material to the floor, the pin and the ball and adjust Bounce etc.  Create a prefab of the ball, then Instantiate it in Unity Script, then give a velocity to the ball and roll it on the floor.  Change the direction of the ball throw: this.transform.rotation = Quaternion.AngleAxis (90, new Vector3 (1, 0, 0)) * Quaternion.AngleAxis (-10 * dir, new Vector3 (0, 0, 1)); Use "Quaternion" for rotation. Use multiplication for a series of rotations around axis. In the above example, it rotates around Z-axis after the rotation around X-axis. Aware of multiplying order.  When you change the throwing position: this.transform.position = new Vector3 (0, 0, -10);  Obtain a Mouse position:  Use "Input.mousePosition.x", "Input.mousePosition.y" If you want to normalize by a screen size, use "Screen.width" to get the screen size.  Make enable to set the pins: Create an empty Game Object (e.g. pins) and drag all the pins to the object. Then drag the "pins" to "Assets" to make a prefab. When you set the group of pins, call "Instantiate()" to instantiate the prefab (like below). Drag the "pins" prefab to the "pinobj" in advance. GameObject pins = (GameObject)Instantiate(pinobj, new Vector3 (0, 0, -10), Quaternion.identity);  Make a button to set the pins: void OnGUI () { if( GUI.Button(new Rect(10, 10, 100, 20), "PIN") ) // Instantiate the pins } }  Clean up the pins: Destroy(pins);  To judge whether the pin fall or remain: Get a child "pin" by calling foreach (Transform child in pins.transform); Then check its orientation by using "child.eulerAngles.x".  Add a score: Display the score by "Label" of GUI.  and so on....

Recommended publications