Skip to content

Instantly share code, notes, and snippets.

View Gojeflone's full-sized avatar
🐽

Jeremy Gouveia Gojeflone

🐽
View GitHub Profile
@Gojeflone
Gojeflone / B17
Created February 17, 2014 02:18
Changing things in components using script
function OnCollisionEnter (myCollision : Collision) {
if(myCollision.gameObject.name == "Floor"){
var myLight : Light = gameObject.Find("Light").GetComponent(Light);
myLight.enabled = true;
myLight.intensity = 5;
}
}
@Gojeflone
Gojeflone / B16
Created February 17, 2014 02:17
Code to switch between scenes in your unity project
function OnCollisionEnter (myCollision : Collision) {
if(myCollision.gameObject.name == "Floor"){
Application.LoadLevel(myLevel);
}
}
@Gojeflone
Gojeflone / B15
Created February 17, 2014 02:17
Adding a component to an object using a script.
function OnCollisionEnter (myCollision : Collision) {
if(myCollision.gameObject.name == "Platform"){
if(!myCollision.gameObject.rigidbody){
myCollision.gameObject.AddComponent(Rigidbody);
}
}
}
@Gojeflone
Gojeflone / B14
Created February 17, 2014 02:16
How to make GUI Text and counters show on screen
function Update () {
Counter++;
guiText.text = "Counter is: "+Counter;
}
@Gojeflone
Gojeflone / B13
Created February 17, 2014 02:15
Detect collisions by using objects invisible to the player
if(myTrigger.gameObject.name == "box"){
Debug.Log("Box went through!");
}
}
@Gojeflone
Gojeflone / B12
Created February 17, 2014 02:15
Using the arrow keys for left and right input axes
function Update () {
var horiz : float = Input.GetAxis("Horizontal");
transform.Translate(Vector3(horiz,0,0));
}
@Gojeflone
Gojeflone / B11
Created February 17, 2014 02:14
Using joints on objects
No Script, just a thing for establishing joints and whatnot.
@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 () {
@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 / 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));
}