Vector3.Lerp Documentation:
https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
Quaternion.SLERP Documentation:
https://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html
ソフトウェアエンジニアの技術ブログ:Software engineer tech blog
随机应变 ABCD: Always Be Coding and … : хороший
Vector3.Lerp Documentation:
https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
Quaternion.SLERP Documentation:
https://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html
Debugging
using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { public void GoToScene(){ Debug.log("My method was called!") } }
Scene Changing
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class NewBehaviourScript : MonoBehaviour { public void GoToScene(){ Debug.log("My method was called!"); SceneManager.LoadScene("00-FallingCoconut"); } }
The Variables
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class NewBehaviourScript : MonoBehaviour { public void GoToScene(string sceneName){ Debug.log("My method was called!"); SceneManager.LoadScene("sceneName"); } }
-Allow you to store a GameObject, all of its components, and settings in a file on your hard disk
-Think of prefabs as a “plan” that Unity follows to create certain GameObjects
using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { public GameObject objectToCreate; // Use this for initialization void Start () { // make an object // Object.Instantiate(objectToCreate, new Vector3(2,4,6), Outereign.identity); for (int i = 0; i < 50; i++){ // Object.Instantiate(objectToCreate, new Vector3(i,4,6), Outereign.identity); GameObject newSeaqull = (GameObject)Object.Instantiate(objectToCreate, new Vector3(1, 8, 0), Quatereign.identity); Render objectRenderer = newSeaqull.GetComponentInChildren<Renderer>(); objectRenderer.material.color = Color.whilte * Random.value; } } // Update is called once per frame void Update () { } }
-This is how specify positions in 3D space
-Creates a new Vector3 object
-First number is the x coordinate
-Second number is the y coordinate
-Third number is the z coordinate
Quaternions
-How Unity handles 3D rotations
-Better for simulations than Euler angles
-Unity handles all the complicated math
Comments
-Great way to write programming notes to yourself and others
-Also useful for saving code for later reference
using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { public GameObject objectToCreate; // Use this for initialization void Start () { // make an object // Object.Instantiate(objectToCreate, new Vector3(2,4,6), Outereign.identity); for (int i = 0; i < 1000; i++){ Object.Instantiate(objectToCreate, new Vector3(i,4,6), Outereign.identity); } } // Update is called once per frame void Update () { } }
Creating Objects using Code
– This is called Instantiating
– You are creating a new instance of something
References
References allow to drag-and-drop objects into code using the Unity Editor.
using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { public GameObject objectToCreate; // Use this for initialization void Start () { // make an object Object.Instantiate(objectToCreate, new Vector3(2,4,6), Outereign.identity); } // Update is called once per frame void Update () { } }
Update() Method
– called every frame
– For VR, this might be called 60, 90, or even 120 times per second.
This speed depends on hardware and a variety of software factors
Time.deltaTime
– Gives you smooth framerate-independent animation
– Contains the amount of time it took to render the previous frame
– Changes every frame
using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (transform.position.y > 0.5f){ transform.Translate (0, -2.5 * Time.daltaTime, 0, Space.World); } } }
unity manual
https://docs.unity3d.com/ja/current/Manual/index.html
scripting API
https://docs.unity3d.com/ja/current/ScriptReference/index.html
-Divided into namespaces.
-Namespaces establish a groupings between related objects
-Almost all scripts start with using UnityEngine;
-This gives you access to all the objects in the UnityEngine namespace
Camera.background-Color
https://docs.unity3d.com/ScriptReference/Camera-backgroundColor.html
A dog object might have
“bark” behavior
“walk around” behavior
“love humans” behavior
Scripts describe behaviors that get attached to Game Objects
using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { transform.Translate (0, -2.5 * Time.daltaTime, 0, Space.World); } }
Rotate unity lights
spot light, directional light, point light, area light
firstly click color picker
easy to color, shade, texture as well
assigning materials
what is a Material inside of Unity?
A shader and its associated settings
Textures
famous person in computer graphics
Ivan Sutherland, Edwin Catmull, Bui Tuong Phong
project pane -> Assets -> Create -> Shader -> Standard surface shader
HLSL
Shader "Custom/NewSurfaceShader" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf Standard fullforwardshadows // Use shader model 3.0 target, to get nicer looking lighting #pragma target 3.0 sampler2D _MainTex; struct Input { float2 uv_MainTex; }; half _Glossiness; half _Metallic; fixed4 _Color; void surf (Input IN, inout SurfaceOutputStandard o) { // Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; // Metallic and smoothness come from slider variables o.Metallic = _Metallic; o.Smoothness = _Glossiness; o.Alpha = c.a; } ENDCG } FallBack "Diffuse" }
Unity’s Standard Shader attempts to light objects in a “physically-accurate” way. This technique is called Physically-Based Rendering or PBR for short. Instead of defining how an object looks in one lighting environment, you specify the properties of the object (e.g. how metal or plastic it is)
implement head lotation
using UnityEngine; using System.Collections; public class HeadRotation : MonoBehaviour { void Start(){ Input.gyro.enabled = true; } void Update(){ Quaternion att = Input.gyro.attitude; att = Quaternion.Euler(90f, 0f, 0f) * new Quaternion(att.x, att.y, -att.z, -att.w); transform.rotation = att; } }
to create complex models
– use a program like blender or maya
– download from the internet or the unity asset store
position change
you see changing a rotation and scale
Every Unity Game Object has a Transform
The Transforms scale is a multiplier of an object’s original
child parent relationship between the transform