Last active
December 24, 2015 01:59
-
-
Save RANUX/6727563 to your computer and use it in GitHub Desktop.
Unity3d + tk2d sprite movement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class MoveSprite : MonoBehaviour | |
{ | |
public tk2dSprite sprite; | |
float Speed = 50f; // 50 meters per second | |
Vector3 TopRightPoint; | |
Vector3 BottomLeftPoint; | |
void Start() | |
{ | |
BottomLeftPoint = Camera.main.ScreenToWorldPoint( Vector3.zero ); | |
TopRightPoint = Camera.main.ScreenToWorldPoint( new Vector3( Screen.width, Screen.height )); | |
} | |
void Update() | |
{ | |
sprite.transform.position += new Vector3( Speed * direction.x * Time.deltaTime, 0.0f, 0.0f ); | |
if ( sprite.transform.position.x >= TopRightPoint.x ) | |
{ | |
direction = Vector3.left; | |
} | |
if ( sprite.transform.position.x <= BottomLeftPoint.x ) | |
{ | |
direction = Vector3.right; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment