Friday, November 17, 2006
Some code...
var speed = 17;
var gravity = 10;
var layerMask = 1 << 8;
var e_rand = 0;
var timex;
var nextMoveTime = 0.0;
var d_counter = 0;
var moveDelay = 5;
var bloat_rand = 4;
var controller : CharacterController;
private var moveDirection = Vector3.zero;
function Update ()
{
var locn = -1;
var loci = -1;
var master_object = GameObject.Find("/MasterGO");
var master_script : MasterGOinit;
master_script = master_object.GetComponent (MasterGOinit);
var hit : RaycastHit;
var ehit : RaycastHit;
//var hit2 : RaycastHit;
var controller : CharacterController = GetComponent(CharacterController);
e_rand = Random.Range(1, 5);
e_rand = Mathf.Round(e_rand);
//bloat_rand = Random.Range(1, 4);
timex = Time.deltaTime * 10;
if (nextMoveTime == 0){
nextMoveTime = Time.time;}
if ((controller.collisionFlags & CollisionFlags.Sides) != 0){
master_script.burgerman = 0;
master_script.respawnb = 1;
counter = master_script.bcount;
counter --;
master_script.bcount = counter;
Destroy(gameObject);}
if (d_counter > 10){
master_script.burgerman = 0;
master_script.respawnb = 1;
counter = master_script.bcount;
counter --;
master_script.bcount = counter;
Destroy(gameObject);}
// if (!(controller.transform.position.x < -64 || controller.transform.position.x > 56 || controller.transform.position.z < -101 || controller.transform.position.z > 20)){
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);//}
Debug.DrawRay (transform.position, Vector3.forward);
locn = master_script.opos[1];
loci = master_script.opos[0];
switch(0){
case 1:
loci++;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[0] = master_script.opos[0] + 1;}
break;
case 2:
loci--;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[0] = master_script.opos[0] - 1;}
break;
case 3:
locn++;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(0, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[1] = master_script.opos[1] + 1;}
case 4:
locn--;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(0, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[1] = master_script.opos[1] - 1;}
break;
}
ehit = hit;
switch (e_rand){
case 1:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.forward,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.forward,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, speed));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("forward!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, speed));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 2:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.back,hit,12)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.back,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, -speed));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("back!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, -speed));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 3:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.right,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.right,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("right!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "mainman") && (ehit.collider.name != "shoeman(Clone)") && (ehit.collider.name != "burgerman(Clone)") && (ehit.collider.name != "oilman(Clone)")){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 4:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.left,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.left,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("left!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "mainman") && (ehit.collider.name != "shoeman(Clone)") && (ehit.collider.name != "burgerman(Clone)") && (ehit.collider.name != "oilman(Clone)")){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
}
}
function Awake ()
{
var controller : CharacterController = GetComponent(CharacterController);
if (!controller)
gameObject.AddComponent("CharacterController");
nextMoveTime = Time.time;
}
var gravity = 10;
var layerMask = 1 << 8;
var e_rand = 0;
var timex;
var nextMoveTime = 0.0;
var d_counter = 0;
var moveDelay = 5;
var bloat_rand = 4;
var controller : CharacterController;
private var moveDirection = Vector3.zero;
function Update ()
{
var locn = -1;
var loci = -1;
var master_object = GameObject.Find("/MasterGO");
var master_script : MasterGOinit;
master_script = master_object.GetComponent (MasterGOinit);
var hit : RaycastHit;
var ehit : RaycastHit;
//var hit2 : RaycastHit;
var controller : CharacterController = GetComponent(CharacterController);
e_rand = Random.Range(1, 5);
e_rand = Mathf.Round(e_rand);
//bloat_rand = Random.Range(1, 4);
timex = Time.deltaTime * 10;
if (nextMoveTime == 0){
nextMoveTime = Time.time;}
if ((controller.collisionFlags & CollisionFlags.Sides) != 0){
master_script.burgerman = 0;
master_script.respawnb = 1;
counter = master_script.bcount;
counter --;
master_script.bcount = counter;
Destroy(gameObject);}
if (d_counter > 10){
master_script.burgerman = 0;
master_script.respawnb = 1;
counter = master_script.bcount;
counter --;
master_script.bcount = counter;
Destroy(gameObject);}
// if (!(controller.transform.position.x < -64 || controller.transform.position.x > 56 || controller.transform.position.z < -101 || controller.transform.position.z > 20)){
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);//}
Debug.DrawRay (transform.position, Vector3.forward);
locn = master_script.opos[1];
loci = master_script.opos[0];
switch(0){
case 1:
loci++;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[0] = master_script.opos[0] + 1;}
break;
case 2:
loci--;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[0] = master_script.opos[0] - 1;}
break;
case 3:
locn++;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(0, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[1] = master_script.opos[1] + 1;}
case 4:
locn--;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(0, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[1] = master_script.opos[1] - 1;}
break;
}
ehit = hit;
switch (e_rand){
case 1:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.forward,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.forward,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, speed));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("forward!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, speed));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 2:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.back,hit,12)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.back,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, -speed));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("back!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, -speed));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 3:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.right,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.right,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("right!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "mainman") && (ehit.collider.name != "shoeman(Clone)") && (ehit.collider.name != "burgerman(Clone)") && (ehit.collider.name != "oilman(Clone)")){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 4:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.left,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.left,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("left!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "mainman") && (ehit.collider.name != "shoeman(Clone)") && (ehit.collider.name != "burgerman(Clone)") && (ehit.collider.name != "oilman(Clone)")){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
}
}
function Awake ()
{
var controller : CharacterController = GetComponent(CharacterController);
if (!controller)
gameObject.AddComponent("CharacterController");
nextMoveTime = Time.time;
}