Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class planeControl : MonoBehaviour {
- public Transform PlayerMove;
- public GameObject PlayerPlane;
- public float speed = 0.5f;
- private bool TouchStart = false;
- private Vector2 pointA;
- private Vector2 pointB;
- public Transform circle;
- void Start()
- {
- }
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- pointA = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,
- Camera.main.transform.position.z));
- circle.transform.position = pointA * 1;
- circle.GetComponent<SpriteRenderer>().enabled = true;
- }
- if (Input.GetMouseButton(0))
- {
- TouchStart = true;
- pointB = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,
- Camera.main.transform.position.z));
- }
- else
- {
- Touchfalse();
- }
- }
- private void FixedUpdate()
- {
- if (TouchStart)
- {
- Vector2 offset = pointB - pointA;
- Vector2 direction = Vector2.ClampMagnitude(offset, 1.0f);
- moveplane(direction * -1);
- circle.transform.position = new Vector2(pointA.x + direction.x, pointA.y + direction.y) * 1;
- }
- else
- {
- circle.GetComponent<SpriteRenderer>().enabled = false;
- }
- }
- public void Touchfalse()
- {
- TouchStart = false;
- }
- void moveplane(Vector2 direction)
- {
- PlayerMove.Translate(-direction * speed * Time.deltaTime);
- }
- //void OnTriggerEnter2D(Collider2D triggerCollider)
- //{
- // if (triggerCollider.tag == "planePlay")
- // {
- // Debug.Log(triggerCollider.name);
- // Destroy(gameObject);
- // }
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement