This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of a simple state machine. | |
// The script has 3 states for different actions it might be performing. It transitions between the states based on user input. | |
// State "start" does nothing; state "slowcube" makes the object named "cube" slow down; state "spiralsphere" makes the sphere object spiral outward. | |
// It can transition from "start" to "slowcube" OR "spiralsphere" depending on what button is hit. | |
// After that, it can transition from "slowcube" to "spiralsphere" or from "spiralsphere" to "slowcube" when fire1 is hit. | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class statemachine : MonoBehaviour { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unity3d example of using Find() and GetComponent() to control one script from another script | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class mcp : MonoBehaviour { | |
void Start () { | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unity3d script to animate many circling objects | |
// Script creates the objects on startup, by instantiating a given object (create a prefab and assign it to the "obj" parameter in the inspector) | |
// Then moves them in a circle in the same way as circleChildren.cs | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class createCirclingChildren : MonoBehaviour { | |
public int numberOfChildren = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unity3D script to move all the children of an object in a circle | |
// Uses "childCount" and "GetChild()" to access all the immediate child nodes | |
// Positions each on a circle, spreading them evenly around the circle | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class circleChildren : MonoBehaviour { | |
public float speed = 1f; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Move an object in a circle in Unity3d, by "driving" | |
// Assumes that the object is currently on the edge of a circle, and computes an angle tangent to that circle | |
// Sets the objects orientation to that angle, and then moves the object "forward" (the "up" vector in this case, since we're working in XY) | |
// Note that moving forward will actually cause the object to move slightly off of its current circle, and thus spiral away from the origin (this becomes more obvious at higher speeds) | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class circle2 : MonoBehaviour { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Minimal Unity3d example of moving an object in a circle | |
// Script determines a current angle, then computes an X & Y for that angle using cos & sin | |
// Object is placed at the computed X,Y by setting the "localPosition" attribute of its transform | |
// Script uses 2 public variables so that you can control the size of the circle and how fast it moves | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class circle1 : MonoBehaviour { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
// Script to visualize earthquake data in GeoJSON format from USGS | |
// (http://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php) | |
// Requires the JSONObject plugin from http://wiki.unity3d.com/index.php/JSONObject | |
// The script should be attached to a model of the Earth such as a sphere | |
// with a 20 unit diameter. A prefab to use for marking the quakes should | |
// be assigned to the variable "prefab" in the Unity editor. | |
import JSONObject; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
// Script to create a Unity mesh containing a sphere | |
// The sphere is warped with a sine wave pattern over time | |
var verts1 : Vector3[]; | |
function Start () { | |
gameObject.AddComponent(MeshFilter); | |
gameObject.AddComponent(MeshRenderer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
// Script that creates a Unity mesh with 2 triangles, with per-vertex colors | |
// Note that this requires the vertexColor shader (https://gist.github.com/davepape/6b74369986ff6324c47a) | |
// to also be in your project's assets | |
function Start () { | |
gameObject.AddComponent(MeshFilter); | |
gameObject.AddComponent(MeshRenderer); | |
GetComponent(Renderer).material = new Material(Shader.Find("Custom/Vertex Colored")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
private var texture: Texture2D; | |
function Start() { | |
var color; | |
var s = new System.IO.File.ReadAllLines('Assets/data/glp00g60.asc'); | |
var ncols = 360; | |
var nrows = 143; | |
texture = new Texture2D(ncols,180); |