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;
- static var playerScore : int;
- var bullet : Rigidbody;
- function Update ()
- {
- // get drag coords
- if (Input.GetButtonDown ("Fire1")) {
- endDrag.x = 0;
- startDrag = Input.mousePosition;
- }
- if (Input.GetButtonUp ("Fire1")) {
- endDrag = Input.mousePosition;
- }
- // calculate drag
- if (startDrag.x != 0 && endDrag.x != 0){
- dragAmt = (endDrag.x - startDrag.x);
- if(dragAmt > 0){
- totalDrag = dragAmt;
- // save state
- shipStartTime = Time.time;
- transform.position = shipLocalPosition;
- dragMove();
- }else{
- totalDrag = 0;
- }
- }
- // 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);
- GUI.Label(Rect(10,90,200,50), "totalDrag: " + totalDrag);
- }
- function dragMove()
- {
- transform.position = Vector3.Lerp(shipLocalPosition,shipLocalPosition + Vector3(2,0,0), ((Time.time - shipStartTime)/2));
- }
Add Comment
Please, Sign In to add comment