1

我已经尝试了所有可能的方法来让它工作但没有成功。我有一个滑动脚本和一个游戏/控制脚本。我试图在我的控制脚本中引用滑动控件作为控制我的角色的方法。到目前为止,我从 Unity 中只收到一个错误。

Assets/RuinRunStarterKit/Scripts/csTempleRun.cs(307,25):错误 CS1501:方法UpdatePlayer' takes0' 参数没有重载

我尝试在 UpdatePlayer 的括号内添加 TouchDetector.enTouchType 但这给了我三个错误,而不仅仅是一个。我联系了许多人并访问了许多网站以寻找答案,但未能产生有效的结果。我没有受过编程教育。我只是在网上研究了如何在编程方面做一些事情。我这里的第二个脚本来自我在 Unity 资源商店购买的资源。我已经联系了他们以获得添加滑动控件的支持,他们通过电子邮件向我发送了触摸脚本,但没有告诉我如何实现它。我只想在手机上玩这个游戏,用滑动作为控件。这是供个人使用的。如果有人可以帮助我达到预期的结果,我将非常感激。再次,我希望能够使用滑动来控制角色。谢谢你。这是我的脚本:

TouchDetector.cs;

    using UnityEngine;
    using System.Collections;

    public class TouchDetector : MonoBehaviour {
public delegate void deTouchEvent
    (enTouchType touchType);

public static event
    deTouchEvent
    evTouchEvent;

public enum enTouchType
{
    SwipeLeft,
    SwipeRight,
    SwipeDown,
    SwipeUp,
}   

void Start ()
{   
}   

void Update ()
{   
    if (evTouchEvent == null)
        return;

    if (Input.GetKeyDown(KeyCode.UpArrow   )) evTouchEvent(enTouchType.SwipeUp   );
    if (Input.GetKeyDown(KeyCode.DownArrow )) evTouchEvent(enTouchType.SwipeDown );
    if (Input.GetKeyDown(KeyCode.LeftArrow )) evTouchEvent(enTouchType.SwipeLeft );
    if (Input.GetKeyDown(KeyCode.RightArrow)) evTouchEvent(enTouchType.SwipeRight);

    if (Input.touchCount > 0)
    {
        foreach (Touch t in Input.touches)
        {
            Vector3 swipe = t.deltaPosition * t.deltaTime;

            if (swipe.y >  0.5f) evTouchEvent(enTouchType.SwipeUp   );
            if (swipe.y < -0.5f) evTouchEvent(enTouchType.SwipeDown );
            if (swipe.x >  0.5f) evTouchEvent(enTouchType.SwipeRight);
            if (swipe.x < -0.5f) evTouchEvent(enTouchType.SwipeLeft );
        }
    }
}
    }

csTempleRun.cs;

    void Update () 
    {   
        UpdatePlayer();

        if (m_player != null)
        {
            // Make the camera follow the player (if active)
            SmoothFollow sF = (SmoothFollow)Camera.mainCamera.GetComponent(typeof(SmoothFollow));
            sF.target = m_player.transform;         

            // Check for collisions with interactive objects
            UpdateCoins();
            UpdateMines();

            // Dynamically update the track
            CreateNewCellsIfNeeded(false);
        }       
    }


    private void UpdatePlayer(TouchDetector.enTouchType T)
{
    // if the player is dead (replaced with ragdoll) then exit since none of this code should fire.
    if (m_player == null) 
    {
        return;     
    }



    // Gradually increase the players' running speed, and update the animation to match.
    m_playerRunSpeed += Time.deltaTime * 0.005f;
    m_playerRunSpeed = Mathf.Clamp(m_playerRunSpeed, 0.5f, 3.0f);
    m_player.animation["run"].speed = m_playerRunSpeed * 2.0f;

    // ****************************************************************************************
    // INPUT

    // Player can only turn if they are not already sliding / jumping.  
    // Equally, sliding / jumping are mutually exclusive.

    if (Input.GetKeyDown (KeyCode.LeftArrow)&& m_playerJump <= -1.0f && m_playerSlide <=0.0f)
    {
        if (m_playerDirection == enCellDir.North) m_playerNextDirection = enCellDir.West;
        if (m_playerDirection == enCellDir.East ) m_playerNextDirection = enCellDir.North;
        if (m_playerDirection == enCellDir.South) m_playerNextDirection = enCellDir.East;
        if (m_playerDirection == enCellDir.West ) m_playerNextDirection = enCellDir.South;
    }

    if (Input.GetKeyDown(KeyCode.RightArrow) && m_playerJump <= -1.0f && m_playerSlide <=0.0f)
    {
        if (m_playerDirection == enCellDir.North) m_playerNextDirection = enCellDir.East;
        if (m_playerDirection == enCellDir.East ) m_playerNextDirection = enCellDir.South;
        if (m_playerDirection == enCellDir.South) m_playerNextDirection = enCellDir.West;
        if (m_playerDirection == enCellDir.West ) m_playerNextDirection = enCellDir.North;
    }   

    if (T==TouchDetector.enTouchType.SwipeDown && m_playerJump <= -1.0f && m_playerSlide <=0.0f)
    {
        m_playerSlide = 1.0f;
        m_player.animation.Play("slide_fake");
    }            

    if ((Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Space)) && m_playerJump <= -1.0f && m_playerSlide <=0.0f)
    {
        AudioSource.PlayClipAtPoint(m_jumpAudio, m_player.transform.position);
        m_playerJump = 1.0f;
        m_playerYvel = 0.0f;
        m_player.animation.Play("jump");
    }

我希望发布此脚本没有做错任何事,但我觉得我需要发布此脚本以获得所需的帮助。您会在 csTempleRun.cs 脚本中注意到,我将其中一个 KeyCode 调用替换为 TouchDetector.enTouchType.SwipeDown。但是我仍然遇到错误。提前感谢您的帮助。也感谢您的时间。

4

2 回答 2

1

看看你的错误 - No overload for method UpdatePlayer' takes0' arguments。这意味着您需要为您的方法提供额外的数据。您需要提供哪些数据智能感知可以告诉您。

于 2013-03-29T15:27:46.640 回答
0

在您的代码中:

void Update () 
{   
    UpdatePlayer(); 
    ...

UpdatePlayer()用零参数调用。但是,UpdatePlayer需要一个论据:

private void UpdatePlayer(TouchDetector.enTouchType T)
{

因此,当您调用 时UpdatePlayer(),您需要发送一个该类型的对象TouchDetector.enTouchType作为参数。那将是以下之一:

  • 向左滑动
  • 向右滑动
  • 刷下
  • 向上滑动
于 2013-03-21T08:42:04.807 回答