unity3d - Unity won't accept my float (JS, 2d) -


i making top down 'atari' type game , ive been having little trouble recently, using transform.position change coordinate on screen using getkey moves little fast, tried use float slow down progression , not moving @ now... here code

 #pragma strict  var xcoor = 0;  var ycoor = 0;        function start () {  }   function update () {           if(input.getkey (keycode.d))          xcoor += 0.5;          transform.position = vector2(xcoor,ycoor);      if(input.getkey (keycode.w))          ycoor += 0.5;          transform.position = vector2(xcoor,ycoor);      if(input.getkey (keycode.a))          xcoor += -0.5;          transform.position = vector2(xcoor,ycoor);      if(input.getkey (keycode.s))          ycoor += -0.5;          transform.position = vector2(xcoor,ycoor);  } 

as can tell im new unity if there better way, please share! thank ;)

i'm not sure, believe xcoor of type int. when try add float it, doesn't change.

change definition of xcoor , ycoor 0.0 instead of 0, , see if works.

#pragma strict var xcoor = 0.0; var ycoor = 0.0;    

also, has been pointed out in comments, should put braces after if statements, unwanted results.

function update () {         if(input.getkey (keycode.d)) {         xcoor += 0.5;         transform.position = vector2(xcoor,ycoor);     }      if(input.getkey (keycode.w)) {         ycoor += 0.5;         transform.position = vector2(xcoor,ycoor);     }      if(input.getkey (keycode.a)) {         xcoor += -0.5;         transform.position = vector2(xcoor,ycoor);     }      if(input.getkey (keycode.s)) {         ycoor += -0.5;         transform.position = vector2(xcoor,ycoor);     } } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -