Prefabs

-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 () {

	}
}

new Vector3(x, y, z)

-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

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

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

Behaviors

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);
	}
}

the Fetch Request

fetch('<URL-to-the-resource-that-is-being-requested>');
fetch('https://api.unsplash.com/search/photos?page=1&query=flowers')

fetch('https://api.unsplash.com/search/photos?page=1&query=${searchedForText}', {
	method: 'POST'
});

[javascriit]
fetch(‘https://api.unsplash.com/search/photos?page=1&query${searchedForText}’, {
headers: {
Authorization: ‘Client-ID abc123’
}
}).then(function(response){
debugger;
});[/javascript]

Since the Unsplash API we’re using will return JSON to us, we just need to call .json() on the response variable.

fetch('https://api.unsplash.com/search/photos?page=1&query${searchedForText}', {
	headers: {
		Authorization: 'Client-ID abc123'
	}	
}).then(function(response){
	return response.json();
});
function addImage(data){
	let htmlContent = '';
	const firstImage = data.result[0];

	if (firstImage){
		htmlContent = '<figure>
			<img src="${firstImage.urls.small}" alt="${searchedForText}">
			<figcaption>${searchedForText} by ${firstImage.user.name}</figcaption>
			</figure>
	} else {
		htmlContent = 'Unfortunately, no image was returned for your search.'
	}

	responseContainer.insertAdjacentHTML('afterbegin', htmlContent);
}

Handling returning error

const imgRequest = new XMLHttpRequest();
imgRequest.onload = addImage;
imgRequest.open('GET', 'https://api.unsplash.com/photos?page=1&query=${searchedForText}');
imgRequest.setRequestHeader('Authorization', 'Client-ID <client-id-here>');
imgRequest.send();
function addImage(){
	const data = JSON.parse(this.responseText);
	const firstImage = datat.results[0];

	responseContainer.insertAdjacementHTML('afterbegin', <figure>
		<img src="${firstImage.urls.small}" alt="${searchedForText}">
		<figcaption>${searchedForText} by ${firstImage.user.name}</figcaption>
		</figure>
		);
}

jQuery ajax()

$.ajax(<url-to-fetch>,<a-configuration-object>);
$.ajax(<just a configuration object>);

var settings = {
	frosting: 'buttercream',
	colors: ['orange', 'blue'],
	layers: 2,
	isRound: true
};

const myDeliciousCake = MakeCake({
	frosting: 'buttercream',
	colors: ['orange', 'blue'],
	layers: 2,
	isRound: true
});

$.ajax({
	url: 'http://swapi.co/api/people/1/'
});
function handleResponse(data){
	console.log('the ajax request has finished!');
	console.log(data);
}

$.ajax({
	url: 'http://swapi.co/api/people/1/'
}).done(handleResponse);