Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity3d如何从另一个脚本引用滑动控件?_C#_Android_Unity3d_Swipe - Fatal编程技术网

C# Unity3d如何从另一个脚本引用滑动控件?

C# Unity3d如何从另一个脚本引用滑动控件?,c#,android,unity3d,swipe,C#,Android,Unity3d,Swipe,我尝试了所有可能的方法,但都没有成功。我有一个滑动脚本和一个游戏/控制脚本。我试图引用我的控制脚本中的滑动控件作为控制角色的手段。到目前为止,我只从团结内部得到一个错误 Assets/RuinRunStarterKit/Scripts/csTempleRun.cs(307,25):错误CS1501:方法UpdatePlayer'采用的参数0'没有重载 我尝试在UpdatePlayer的括号内添加TouchDetector.enTouchType,但这给了我三个错误,而不是一个。我联系了很多人,访

我尝试了所有可能的方法,但都没有成功。我有一个滑动脚本和一个游戏/控制脚本。我试图引用我的控制脚本中的滑动控件作为控制角色的手段。到目前为止,我只从团结内部得到一个错误

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

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

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 );
        }
    }
}
    }
使用UnityEngine;
使用系统集合;
公共类触控检测器:单行为{
公共委托无效deTouchEvent
(触控式);
公共静态事件
deTouchEvent
事件;
公共枚举类型
{
SwipeLeft,
SwipeRight,
SwipeDown,
游泳,
}   
无效开始()
{   
}   
无效更新()
{   
如果(evTouchEvent==null)
返回;
if(Input.GetKeyDown(KeyCode.UpArrow))evTouchEvent(enTouchType.SwipeUp);
if(Input.GetKeyDown(KeyCode.DownArrow))evTouchEvent(enTouchType.SwipeDown);
if(Input.GetKeyDown(KeyCode.LeftArrow))evTouchEvent(enTouchType.swipleft);
if(Input.GetKeyDown(KeyCode.RightArrow))evTouchEvent(enTouchType.SwipeRight);
如果(Input.touchCount>0)
{
foreach(在Input.touchs中触摸t)
{
向量3滑动=t.deltaPosition*t.deltaTime;
如果(swipe.y>0.5f)evTouchEvent(enTouchType.SwipeUp);
如果(滑动y<-0.5f)evTouchEvent(enTouchType.SwipeDown);
如果(swipe.x>0.5f)evTouchEvent(enTouchType.SwiperRight);
如果(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");
    }
void更新()
{   
UpdatePlayer();
if(m_player!=null)
{
//使相机跟随播放器(如果激活)
SmoothFollow sF=(SmoothFollow)Camera.mainCamera.GetComponent(类型(SmoothFollow));
sF.target=m_player.transform;
//检查与交互对象的碰撞
UpdateCoins();
UpdateMines();
//动态更新轨迹
CreateNewCellsIfNeeded(false);
}       
}
私有void更新层(TouchDetector.enTouchType T)
{
//如果玩家死亡(被碎布玩偶替换),则退出,因为此代码不应触发。
如果(m_player==null)
{
返回;
}
//逐渐提高玩家的跑步速度,并更新动画以匹配。
m_playerUnspeed+=Time.deltaTime*0.005f;
m_PlayerUnspeed=主夹具(m_PlayerUnspeed,0.5f,3.0f);
m_player.animation[“run”]。速度=m_playerUnspeed*2.0f;
// ****************************************************************************************
//输入
//玩家只有在没有滑/跳的情况下才能转身。
//同样,滑行/跳跃是相互排斥的。
如果(Input.GetKeyDown(KeyCode.LeftArrow)和&m_playerJump在代码中:

void Update () 
{   
    UpdatePlayer(); 
    ...
使用零参数调用
UpdatePlayer()
。但是,
UpdatePlayer
需要一个参数:

private void UpdatePlayer(TouchDetector.enTouchType T)
{
因此,当调用
UpdatePlayer()
时,需要将类型为
TouchDetector.enTouchType
的对象作为参数发送。这将是以下之一:

  • 游泳池
  • 泳镜
  • 游泳池
  • 游泳
在您的代码中:

void Update () 
{   
    UpdatePlayer(); 
    ...
使用零参数调用
UpdatePlayer()
。但是,
UpdatePlayer
需要一个参数:

private void UpdatePlayer(TouchDetector.enTouchType T)
{
因此,当调用
UpdatePlayer()
时,需要将类型为
TouchDetector.enTouchType
的对象作为参数发送。这将是以下之一:

  • 游泳池
  • 泳镜
  • 游泳池
  • 游泳

查看您的错误-
方法更新层'takes0'参数没有重载。
这意味着您需要为您的方法提供额外的数据。需要提供intellisense的哪些数据可以告诉您。

查看您的错误-
方法更新层'takes0'参数没有重载。
这意味着您需要支持向您的方法添加额外的数据。您需要提供intellisense的哪些数据可以告诉您。

我想我理解正确了。我将TouchDetector.enTouchType T移动到Update()中的UpdatePlayer()的第一个调用方法,但这给了我多个错误。我需要使用所有四个滑动方向。我想我正确地理解了您的意思。我将TouchDetector.enTouchType T移动到Update()中对UpdatePlayer()的第一个调用方法,但这给了我多个错误。我需要使用所有四个滑动方向。哥们,你可以按“-1”按钮100次,如果你连编译器消息都看不懂,我应该跟你说什么?阅读书籍…哥们,你可以按“-1”按钮100次,如果你连编译器消息都看不懂,我应该跟你说什么?阅读书籍。。。