如何用几下水龙头固定?

问题描述 投票:0回答:1

我有一个字符轮换,它是基于此的。有操纵杆。如果您先将手指放在角色旋转上,然后再放在操纵杆上-一切都很好。但是,如果首先在操纵杆上,然后尝试转弯,则什么也不会发生!帮帮我。几天不能决定

 void Start()
    {
        mContr = GameObject.FindGameObjectWithTag("Joystick").GetComponent<MobileController>();
    }

    void Update()
    {
        if(xp > 0)
        {
            deadStatus = false;
            ch_animator.SetBool("dead", false);
        }
        if(xp <= 0)
        {   if(deadStatus == false)
            {
                menu.gameObject.SetActive(false);
                ch_animator.SetBool("Run", false);
                ch_animator.SetBool("Walk", false);
                ch_animator.SetBool("right", false);
                ch_animator.SetBool("left", false);
                ch_animator.SetBool("dead", true);
                dead.gameObject.SetActive(true);
                if(GameObject.Find("selectLvl"))
                {
                    GameObject.Find("selectLvl").SetActive(false);
                }
                if(GameObject.Find("settings"))
                {
                    GameObject.Find("settings").SetActive(false);
                }
                deadStatus = true;
            }
        }
        if(eat > 10)
        {
            if(xp>0&&xp!=100) {
                xp += Time.deltaTime * 1f;
                eat -= Time.deltaTime * 0.5f;
            }
            speedMove = 3;
        } else {
            speedMove = 1;
            if(eat < 1 ) {
                xp -= Time.deltaTime * 0.06f;
            }
        }
        if(xp.ToString() != hpText.text) {
            hpText.text = Math.Round(xp).ToString();
        }
        if(eat.ToString() != eatText.text)
        {
            eatText.text = Math.Round(eat).ToString();
        }
        if(star.ToString() != starText.text)
        {
            starText.text = star.ToString();
        }
        if(gun.ToString() != gunText.text)
        {
            gunText.text = gun.ToString();
        }
        int k = 1;
        while(Input.touchCount > k)
        {
            Vector2 deltaposition = Vector2.zero;
            if(Input.GetTouch(k).position.x > Screen.width / 2 - 100)
            {
                if(k == 0)
                    deltaposition = Input.GetTouch(k).deltaPosition;
                deltaposition.x /= Screen.dpi;
                if(deltaposition.x != 0)
                {
                    float speedX = 3 * deltaposition.x;
                    player.transform.Rotate(Vector3.up * speedX);
                }
            }
            k++;
        }


        CharacterMove();
        GameGravity();
    }

邮政编码

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class MobileController: MonoBehaviour, IDragHandler, IPointerUpHandler, IPointerDownHandler
{
    private Image jostickBG;
    [SerializeField]
    private Image jostick;
    public Vector2 inputVector;
    private void Start()
    {
        jostickBG = GetComponent<Image>();
        jostick = transform.GetChild(0).GetComponent<Image>();
    }

    public virtual void OnPointerDown(PointerEventData ped)
    {

    }
    public virtual void OnPointerUp(PointerEventData ped)
    {
        inputVector = Vector2.zero;
        jostick.rectTransform.anchoredPosition = Vector2.zero;
    }

    public virtual void OnDrag(PointerEventData ped)
    {
        Vector2 pos;
        if(RectTransformUtility.ScreenPointToLocalPointInRectangle(jostickBG.rectTransform, ped.position, ped.pressEventCamera, out pos))
        {
            pos.x = (pos.x / jostickBG.rectTransform.sizeDelta.x);
            pos.y = (pos.y / jostickBG.rectTransform.sizeDelta.y);
            inputVector = new Vector2(pos.x * 2 - 0, pos.y * 2 - 0);
            inputVector = (inputVector.magnitude > 1.0f) ? inputVector.normalized : inputVector;
            jostick.rectTransform.anchoredPosition = new Vector2(inputVector.x * (jostickBG.rectTransform.sizeDelta.x / 2), inputVector.y * (jostickBG.rectTransform.sizeDelta.y / 2));
        }
    }

    public float Horizontal()
    {
        return inputVector.x;
    }

    public float Vertical()
    {
        return inputVector.y;
    }
}
c# android ios unity3d touch
1个回答
0
投票

问题来自while循环:

您的逻辑仅对于旋转播放器上的k = 0和k = 1表示喜悦,您开始以值k = 1进入while循环,如果此值是其位置,则测试if是否始终为false旋转播放器

if(Input.GetTouch(k).position.x > Screen.width / 2 - 100)

我建议您这样重构代码:

[当您有2次触摸,k = 0和k = 1时,为每次触摸找到正确的动作。

我不知道为什么您不以k = 0进入while循环?

© www.soinside.com 2019 - 2024. All rights reserved.