Hack Forums
[Help] Unity with javascript(unityscript) issues - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Help] Unity with javascript(unityscript) issues (/showthread.php?tid=4712854)



Unity with javascript(unityscript) issues - RAMSEY111 - Mar 2, 2015

I would post this in the Java section but I don't think they except Java Script there maybe I'm wrong I just don't want to piss any one off. any way I've been learning java for the unity game engine and I've been trying to program a cube to move from side to side on the screen. this was coed that I learned from a tutorial but then to try and practice it I attempted to write a segment to make it go up and down as well. Something went wrong and now the cube still goes from side to side but then it goes to the highest point that I've specified (9 units high) then stays there and doesn't come back down. It does how ever continue to move back and fourth across the screen it just down't go up and down. Here's the code:
Code
var speed : float = 5; // units per second
var speedTwo : float = 3;
private var goingPositive : boolean = true;
private var upDown : boolean = true;

function Update () {
    if(goingPositive == true) {
    transform.position.x += speed * Time.deltaTime;
    }
    else{
    transform.position.x -= speed * Time.deltaTime;
    }
    if(transform.position.x > 20){
    goingPositive = false;
    }
    if(transform.position.x < -20){
    goingPositive = true;
    }
    // begining of my addition to the code <------
    if(upDown == true){
    transform.position.y += speedTwo * Time.deltaTime;
    }
    else{
    transform.position.y -= speedTwo * Time.deltatime;
    }
    if(transform.position.y < .60){
    upDown = true;
    }
    if(transform.position.y  >= 9){
    upDown = false;
    }
}

Just as a side note I think I used the code tags correct but I'm not sure so if I didn't I'll try and figure them out as fast as I can. Sorry for any inconvenience.