android - Who to limit Sprite with tilt control, to screen boundaries? -


im trying limit sprite screen edges. i'm using script unity manual , i've added clamp movement. issue screen bounded different each resolution, , cant figure out how use "camera.worldtoviewportpoint" in here... bound 0.1f , 0.9f want replace real screen bounds or size. atm working sprite moving in small bounds , not real screen size. please :)

here code far:

public float speed = 10.0f; public float posx; public float posy;  void update() {     vector3 dir = vector3.zero;     dir.x = input.acceleration.x;     dir.y = input.acceleration.y;     if (dir.sqrmagnitude > 1)         dir.normalize ();      dir *= time.deltatime;     transform.translate (dir * speed);      transform.position = new vector3(mathf.clamp(transform.position.x, 0.1f, 0.9f),mathf.clamp(transform.position.y, 0.1f, 0.9f), 0); } 


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -