Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class planeControl : MonoBehaviour {
  6. public Transform PlayerMove;
  7. public GameObject PlayerPlane;
  8. public float speed = 0.5f;
  9. private bool TouchStart = false;
  10. private Vector2 pointA;
  11. private Vector2 pointB;
  12. public Transform circle;
  13.  
  14. void Start()
  15. {
  16.  
  17. }
  18.  
  19. void Update()
  20. {
  21. if (Input.GetMouseButtonDown(0))
  22. {
  23.  
  24. pointA = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,
  25. Camera.main.transform.position.z));
  26. circle.transform.position = pointA * 1;
  27. circle.GetComponent<SpriteRenderer>().enabled = true;
  28.  
  29. }
  30. if (Input.GetMouseButton(0))
  31. {
  32. TouchStart = true;
  33. pointB = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,
  34. Camera.main.transform.position.z));
  35. }
  36. else
  37. {
  38. Touchfalse();
  39. }
  40.  
  41. }
  42.  
  43. private void FixedUpdate()
  44. {
  45. if (TouchStart)
  46. {
  47. Vector2 offset = pointB - pointA;
  48. Vector2 direction = Vector2.ClampMagnitude(offset, 1.0f);
  49. moveplane(direction * -1);
  50. circle.transform.position = new Vector2(pointA.x + direction.x, pointA.y + direction.y) * 1;
  51. }
  52. else
  53. {
  54. circle.GetComponent<SpriteRenderer>().enabled = false;
  55.  
  56. }
  57. }
  58. public void Touchfalse()
  59. {
  60. TouchStart = false;
  61. }
  62.  
  63. void moveplane(Vector2 direction)
  64. {
  65. PlayerMove.Translate(-direction * speed * Time.deltaTime);
  66. }
  67.  
  68. //void OnTriggerEnter2D(Collider2D triggerCollider)
  69. //{
  70. // if (triggerCollider.tag == "planePlay")
  71. // {
  72. // Debug.Log(triggerCollider.name);
  73. // Destroy(gameObject);
  74. // }
  75.  
  76. //}
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement