Skip to content

Instantly share code, notes, and snippets.

View Gojeflone's full-sized avatar
🐽

Jeremy Gouveia Gojeflone

🐽
View GitHub Profile
@Gojeflone
Gojeflone / B01
Created February 17, 2014 02:02
On Collision
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "Floor"){
Debug.Log("Hit the floor");
}else if(theCollision.gameObject.name == "Wall"){
Debug.Log("Hit the wall");
}
}
@Gojeflone
Gojeflone / B02
Created February 17, 2014 02:02
Detects when a button is let go.
if(Input.GetButtonUp("Jump")){
Debug.Log("We Have Hit the Space Bar!");
}
}
@Gojeflone
Gojeflone / B03
Created February 17, 2014 02:04
Creating a prefab in Unity.
You can save the settings for an object and duplicate it by using a prefab. Under project in Unity, just select prefab and then drag your object on the prefab icon. And Presto, your prefab is created.
@Gojeflone
Gojeflone / B04
Created February 17, 2014 02:04
Destroying objects in Unity
function Start () {
Destroy(gameObject.Find("Box"), 3);
}
@Gojeflone
Gojeflone / B05
Created February 17, 2014 02:06
Instantly create objects while the game is running by using instantiate.
var thePrefab : GameObject;
function Start () {
var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
}
@Gojeflone
Gojeflone / B06
Created February 17, 2014 02:08
Make a simple timer in Unity.
var myTimer : float = 5.0;
function Update () {
if(myTimer > 0){
myTimer -= Time.deltaTime;
}
if(myTimer <= 0){
Debug.Log("GAME OVER");
}
}
@Gojeflone
Gojeflone / B07
Created February 17, 2014 02:10
Make Objects in Unity move using the transform.Translate command.
var speed : float = 5.0;
function Update () {
transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
}
@Gojeflone
Gojeflone / B08
Created February 17, 2014 02:10
Make a rigidbody move by force
var power : float = 500.0;
function Start () {
rigidbody.AddForce(Vector3(0,0,power));
}
@Gojeflone
Gojeflone / B09
Created February 17, 2014 02:12
Add textures to objects using materials
There's no script for this really.
Just select your object and change the element below the mesh renderer.
@Gojeflone
Gojeflone / B10
Created February 17, 2014 02:13
Play sound in Unity
//Using Play One Shot
var myClip : AudioClip;
function Start () {
audio.PlayOneShot(myClip);
//Using Play Clip at point
var myClip : AudioClip;
function Start () {