Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // default vars
- var playerSpeed : int;
- var playerLives : int;
- var startDrag : Vector3;
- var endDrag : Vector3;
- var totalDrag : int;
- var shipLocalPosition : Vector3;
- var shipStartTime : float;
- var moving : boolean;
- static var playerScore : int;
- var bullet : Rigidbody;
- function Update ()
- {
- // get drag coords
- if (Input.GetButtonDown ("Fire1")) {
- startDrag = Input.mousePosition;
- }
- if (Input.GetButtonUp ("Fire1")) {
- endDrag = Input.mousePosition;
- shipStartTime = Time.time;
- moving = true;
- dragAmt = (endDrag.x - startDrag.x);
- }
- // calculate drag
- if (moving)
- {
- dragMove();
- }
- // amount to move player
- amtToMove = (playerSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime;
- // move / translate player
- transform.Translate(Vector3.right * amtToMove);
- if(Input.GetKeyDown("space"))
- {
- var tempBullet : Rigidbody;
- tempBullet = Instantiate(bullet, transform.position, transform.rotation);
- }
- }
- function OnGUI()
- {
- GUI.Label(Rect(10,10,200,50), "Score: " + playerScore);
- GUI.Label(Rect(10,30,200,50), "Lives: " + playerLives);
- GUI.Label(Rect(10,50,200,50), "StartDrag: " + startDrag.x);
- GUI.Label(Rect(10,70,200,50), "EndDrag: " + endDrag.x);
- }
- function dragMove()
- {
- float animationTime = (Time.time - shipStartTime);
- float animationDuration = 2.0;
- transform.position = Vector3.Lerp(shipLocalPosition,shipLocalPosition + Vector3(2,0,0), animationTime / animationDuration );
- if (animationTime > animationDuration)
- {
- moving = false;
- }
- }
Add Comment
Please, Sign In to add comment