Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Help 

Unity with javascript(unityscript) issues

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.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by NottellinhJan 11, 2014 05:07 PM 1 67 Jan 11, 2014 05:07 PM
Last Post: monkeytherat
by danyeOct 11, 2011 06:06 PM 2 43 Oct 11, 2011 06:06 PM
Last Post: danye
by DungAug 6, 2011 03:40 PM 8 122 Aug 6, 2011 03:40 PM
Last Post: SB91