Hi I am new to js and unity and need a little help as I can’t find much info on what I am doing.
I am making a pipe game and at the end of game play I need to detect if the pipes are connected so I can call the win or lose function. I have set a raycast direction to each pipe where applicable and have added the tag “pipe” to each pipe to check for the connection in a for loop, see code
var myTimer : float = 5.0;
var userHasWon = true;
var isConnectedDown: boolean;
var isConnectedUp: boolean;
var isConnectedLeft: boolean;
var isConnectedRight: boolean;
// countdown timer
function Update () {
if(myTimer > 0){
myTimer -= Time.deltaTime;
}
if(myTimer <= 0){
CheckAllPipeConnections();
Debug.Log("Game Over Sucker.............. Checking if all pipes are connected");
}
}
function CheckAllPipeConnections() {
//z axis
var castUp : Vector3 = transform.TransformDirection (0, 10, 0);
var castDown : Vector3 = transform.TransformDirection (0, -10, 0);
//x axis
var castLeft : Vector3 = transform.TransformDirection (-10, 0, 0);
var castRight : Vector3 = transform.TransformDirection (10, 0, 0);
var hit : RaycastHit;
for (var pipe : GameObject in GameObject.FindWithTag("Pipe")) {
if (userHasWon) {
if (pipe.connectDown) {
print("This works");
if (Physics.Raycast( pipe.transform.position, castDown, hit, 0.5 )) {
print("there is indeed a pipe beneath this one, " + pipe.name);
CheckPipe(pipe.transform, -castDown);
}
}
}
}
}
function CheckPipe(pipeToCheck : Transform, directionToCheck : Vector3) {
var hitInOppositeDirection;
if ( !Physics.Raycast ( pipeToCheck.position, directionToCheck, hitInOppositeDirection, 0.5 ) ) {
userHasWon = false;
print("user Has Lost");
}
}
Although I am getting this error when entering play mode
ApplicationException: Argument is not enumerable (does not implement System.Collections.IEnumerable).
Boo.Lang.Runtime.RuntimeServices.GetEnumerable (System.Object enumerable)
UnityScript.Lang.UnityRuntimeServices.GetEnumerator (System.Object obj)
CountDownTimer.CheckAllPipeConnections () (at Assets/Script/CountDownTimer.js:45)
CountDownTimer.Update () (at Assets/Script/CountDownTimer.js:23)
I would really appreciate any help thanks