c# - Unity3d 2d Help transforming code to drag touch -
c# - Unity3d 2d Help transforming code to drag touch -
i want transform game android , it's pong. want able drag paddle on phone. ahead of time help. here's oldest code:
using unityengine; using system.collections; public class moveracket : monobehaviour { public float speed = 30; public string axis = "vertical"; void fixedupdate () { float v = input.getaxisraw (axis); getcomponent<rigidbody2d> ().velocity = new vector2 (0, v) * speed; } }
heres old code it's still not working.
using unityengine; using system.collections; public class moveracket : monobehaviour { public float speed = 30; public string axis = "vertical"; public object racket = "racket"; public bool touchinput = true; public vector2 touchpos; void fixedupdate () { //used not have in parentheses float v = input.getaxisraw (axis); //getcomponent<rigidbody2d> ().velocity = new vector2 (0, v) * speed; if (input.touchcount == 1) { vector3 wp = camera.main.screentoworldpoint(input.gettouch(0).position); vector2 touchpos = new vector2(wp.x, wp.y); if (racket == physics2d.overlappoint(touchpos)); { getcomponent<rigidbody2d> ().velocity = new vector2 (0, v) * speed; } } } }
heres current code. has errors- collider2d type used variable possible mistaken empty statement same line
cannot modify homecoming value trasnform.posistion because it's variable cannot implictiy convert type vector3 float
using unityengine; using system.collections; public class moveracket : monobehaviour { public float speed = 30; public string axis = "vertical"; public object racket = "racket"; public bool touchinput = true; public vector2 touchpos; void fixedupdate () { //used not have in parentheses //float v = input.getaxisraw (axis); float v = input.getaxisraw (axis); getcomponent<rigidbody2d> ().velocity = new vector2 (0, v) * speed; if (input.touchcount == 1) { vector3 wp = camera.main.screentoworldpoint(input.gettouch(0).position); vector2 touchpos = new vector2(wp.x, wp.y); if (collider2d == physics2d.overlappoint(touchpos)); { this.transform.position.y = new vector3 (wp.y,0); } } } }
you saying want drag , need touch first need check touch if user touching screen raycast2d check if touching paddle , utilize same logic maintain @ positon of finger used mouse .
first seek , utilize hint http://answers.unity3d.com/questions/577314/how-to-detect-if-a-sprite-was-object-was-touched-i.html
thank
c# android unity3d touch 2d
Comments
Post a Comment