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);
}
}
}

No comments:

Post a Comment