Skip to content

Instantly share code, notes, and snippets.

View Gojeflone's full-sized avatar
🐽

Jeremy Gouveia Gojeflone

🐽
View GitHub Profile
@Gojeflone
Gojeflone / B27
Created February 17, 2014 02:53
Pause the game by using Time.Scale
var paused : boolean = false;
function Update () {
if(Input.GetButtonUp("Jump")){
if(!paused){
Time.timeScale = 0;
paused=true;
}else{
Time.timeScale = 1;
paused=false;
@Gojeflone
Gojeflone / B26
Created February 17, 2014 02:32
Restricting values with "Mathf.clamp"
function Update () {
var xMove : float = Input.GetAxis("Horizontal") * Time.deltaTime * 20;
transform.Translate(Vector3(xMove,0,0));
transform.position.x = Mathf.Clamp(transform.position.x, -10, 10);
}
@Gojeflone
Gojeflone / B25
Last active August 29, 2015 13:56
Gui textures and enabling a mouse to cause an event on it
var normalTex : Texture2D;
var hoverTex : Texture2D;
function OnMouseEnter () {
guiTexture.texture = hoverTex;
}
function OnMouseExit(){
guiTexture.texture = normalTex;
}
@Gojeflone
Gojeflone / B24
Created February 17, 2014 02:30
For loops in Unity
var myPrefab : Rigidbody;
var distanceMultiplier : float = 2;
function Start(){
var i : int = 0;
var pos : Vector3 = transform.position;
for(i=0; i<=3; i++){
Instantiate(myPrefab, Vector3(pos.x+i*distanceMultiplier, pos.y, pos.z), transform.rotation);
@Gojeflone
Gojeflone / B23
Created February 17, 2014 02:30
Creating a simple explosion using the particle system
var stars : ParticleEmitter;
function OnCollisionEnter (col : Collision) {
Instantiate(stars, transform.position, transform.rotation);
Destroy(gameObject);
}
@Gojeflone
Gojeflone / B22
Created February 17, 2014 02:29
Putting a pause in a script by using "WaitforSeconds"
var box : GameObject;
var readynow : boolean = true;
function Update () {
if(readynow){
MakeBox();
}
}
function MakeBox(){
@Gojeflone
Gojeflone / B21
Created February 17, 2014 02:28
Finding the distance between two points in 3D
var box : Transform;
function Update () {
var dist : float = Vector3.Distance(box.position, transform.position);
Debug.Log(dist);
if(dist <= 10){
light.enabled = true;
}else{
@Gojeflone
Gojeflone / B20
Created February 17, 2014 02:27
If Statements and boo leans in Unity
var myCheck : boolean = true;
function Update () {
if(myCheck){
guiText.text = "Its on!";
}else{
guiText.text = "Its Off!";
}
@Gojeflone
Gojeflone / B19
Created February 17, 2014 02:19
Make objects rotate to face each other using the "LookAt" function
var myTransform : Transform;
function Update () {
transform.LookAt(myTransform);
}
@Gojeflone
Gojeflone / B18
Created February 17, 2014 02:18
Distinguish between local and world directions in script
function Update () {
//transform.Translate(Vector3(0,0,1) * Time.deltaTime);
var fwd = transform.forward * 100;
rigidbody.AddForce(fwd);
}