Saturday, July 31, 2010

Sand Puzzle

I managed to condence the scripts down so I can prefab one row otherwise it took me 20+ scripts to get it working non bugged notice the "var script : sandmovement = gameObject.GetComponentInChildren(sandmovement);" anything parented to the game object can be grabbed with this script.

control box:

function OnTriggerStay(other: Collider) {
if (other.gameObject.tag == "Player") {
var script : sandmovement = gameObject.GetComponentInChildren(sandmovement);
script.moving = true;
}
}
function OnTriggerExit(other: Collider) {
if (other.gameObject.tag == "Player") {
var script : sandmovement = gameObject.GetComponentInChildren(sandmovement);
script.moving=false;
}
}


Sand Movement:

var moving = false;
var reveresed =false;
function Update () {
if(moving && reveresed){
rigidbody.transform.Translate(Vector3.down * 1* Time.deltaTime);
}
if (moving && !reveresed) {
rigidbody.transform.Translate(Vector3.up * 1* Time.deltaTime);
}
}
function OnTriggerEnter(other: Collider) {
if (other.gameObject.tag == "botcollider") {
reveresed = false;
}
if (other.gameObject.tag == "topcollider") {
reveresed = true;
}
}

Message Box:

function OnTriggerEnter(other: Collider) {
if (other.gameObject.tag == "sand") {
finalbox.touch1+=1;
}
}
function OnTriggerExit(other: Collider) {
if (other.gameObject.tag == "sand") {
finalbox.touch1-=1;
}
}

Final box:

static var touch1 = 0;
var minion: GameObject;
var puzzle: GameObject;

function OnTriggerStay(other: Collider) {
if (other.gameObject.tag == "Player") {

if(touch1 == 5){
Destroy(puzzle);
}
else{
Destroy(minion);
}
}
}

File Organization

Hey guys try to build your unity project files just like this example see bottom


prefabs in the player folder


fbx files for unity to ref


seperate folder for scenes

organized script folder


organized project folder