더블 로터 디자인 사고방식

더블 로터 디자인 사고방식
using UnityEngine;
using System.Collections;
   
public enum JoyStickType
{
leftJoyStick,
rightJoyStick
}
   
public class JoyStick : MonoBehaviour {
public JoyStickType joyStickType;//    ,        
public Vector2 centerPos;//        ,    
public Transform centerBall;//     
public float joyStickRadius;//     ,        
private int lastFingerID = -1;//         id
private bool centerBallMoving = false;//         
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
JoyStickController();
}
void JoyStickController()
{
int count = Input.touchCount;//      
for (int i = 0; i < count; i++)//      
{
Touch touch = Input.GetTouch(i);Unity3D    
//               
Vector2 currentTouchPos = new Vector2(Camera.main.ScreenToWorldPoint(touch.position).x, Camera.main.ScreenToWorldPoint(touch.position).y);
Vector2 temp = currentTouchPos - centerPos;//      temp(           )
if (touch.phase == TouchPhase.Began)
{
if (Mathf.Round(temp.magnitude) <= joyStickRadius)//      temp            
{
lastFingerID = touch.fingerId;//      id
centerBallMoving = true;//           
}
}
//          ,             。       ,                 ,           ;
//            ,                              
if (touch.fingerId == lastFingerID && centerBallMoving)
{
if (Mathf.Round(temp.magnitude) <= joyStickRadius) //                 ,     ,              
{
centerBall.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, Camera.main.WorldToScreenPoint(centerBall.transform.position).z));
}
else
{
temp.Normalize();
   //                 ,           z    18,  x,y ,            
centerBall.transform.position = new Vector3((temp * joyStickRadius + centerPos).x, (temp * joyStickRadius + centerPos).y, 18);
}
   
if (temp.x >= 0)//0-180
{
//       :      ,    Vector2.Angle(temp, new Vector2(0, 5))       
   //initialization_script.current_player_tank_script.BodyRotation(Vector2.Angle(temp, new Vector2(0, 5)));
}
if (temp.x< 0)//180-360
{
                   //       :      ,    Vector2.Angle(temp, new Vector2(0, 5))       
//initialization_script.current_player_tank_script.BodyRotation(-1 * Vector2.Angle(temp1, new Vector2(0, 5)));
}
//                ,         ,       
   switch(joyStickType)
   {
    case JoyStickType.leftJoyStick:
    //Move();
    break;
    case JoyStickType.rightJoyStick:
    //Fire()
    break;
   }
   //               
if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
{
                         centerBall.transform.position = new Vector3(centerPos.x, centerPos.y, 18);
    //     ,        initialization_script.current_player_tank_script.CoverRotation(initialization_script.current_player_tank.transform.eulerAngles.y);
          centerBallMoving = false;
lastFingerID = -1;
}
}
}
}
}

좋은 웹페이지 즐겨찾기