Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.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# OnTiggerEnter2D不';我根本不工作。Unity此消息参数的类型必须为R2D_C#_Unity3d - Fatal编程技术网

C# OnTiggerEnter2D不';我根本不工作。Unity此消息参数的类型必须为R2D

C# OnTiggerEnter2D不';我根本不工作。Unity此消息参数的类型必须为R2D,c#,unity3d,C#,Unity3d,我显然做错了什么。团结给了我: 脚本错误:OnTiggerEnter2D此消息参数必须为 类型:R2D 我在一个空的物体上有一个BoxCollider,它是我的玩家的孩子。当它碰撞时,什么也不会发生。我已将IsTrigger设置为true 玩家的子脚本: public class EnemyHurtCollider : MonoBehaviour { private Rigidbody2D rb; private Collider2D coll; private void

我显然做错了什么。团结给了我:

脚本错误:OnTiggerEnter2D此消息参数必须为 类型:R2D

我在一个空的物体上有一个BoxCollider,它是我的玩家的孩子。当它碰撞时,什么也不会发生。我已将IsTrigger设置为true

玩家的子脚本:

public class EnemyHurtCollider : MonoBehaviour
{
    private Rigidbody2D rb;
    private Collider2D coll;
    private void Start()
    {
        GameObject.Find("Player").GetComponent<PlayerController>();
        rb = GameObject.Find("Player").GetComponent<Rigidbody2D>();
        coll = GetComponent<Collider2D>();
    }
    public void OnTriggerEnter2D(Collision2D other)
    {
        if (other.gameObject.tag == "Enemy")
        {
            GameObject.Find("Player").GetComponent<PlayerController>().state = State.hurt; //state hurt
            if (other.gameObject.transform.position.x > transform.position.x)
            {
                Debug.Log("HURT");
                //if enemy is to my right when colliding I should be damaged and move left
                rb.velocity = new Vector2(-GameObject.Find("Player").GetComponent<PlayerController>().hurtForce, rb.velocity.y);
            }
            else
            {
                Debug.Log("HURT");
                //if enemy is to my left when colliding I should be damaged and move right
                rb.velocity = new Vector2(GameObject.Find("Player").GetComponent<PlayerController>().hurtForce, rb.velocity.y);
            }
        }
    }
}
公共类EnemyHurtCollider:MonoBehavior
{
私有刚体2d rb;
私人住宅;
私有void Start()
{
GameObject.Find(“Player”).GetComponent();
rb=GameObject.Find(“Player”).GetComponent();
coll=GetComponent();
}
公共无效OnTiggerEnter2D(碰撞2D其他)
{
如果(other.gameObject.tag==“敌人”)
{
GameObject.Find(“Player”).GetComponent().state=state.hurt;//state-hurt
if(other.gameObject.transform.position.x>transform.position.x)
{
Debug.Log(“hert”);
//如果敌人在我的右边相撞,我应该受到伤害并向左移动
rb.velocity=newvector2(-GameObject.Find(“Player”).GetComponent().hurtForce,rb.velocity.y);
}
其他的
{
Debug.Log(“hert”);
//如果敌人在我的左边相撞,我应该受到伤害并向右移动
rb.velocity=newvector2(GameObject.Find(“Player”).GetComponent().hurtForce,rb.velocity.y);
}
}
}
}

这些是正确的签名:

        private void OnTriggerEnter2D(Collider2D other)
        {
            throw new NotImplementedException();
        }

        private void OnTriggerExit2D(Collider2D other)
        {
            throw new NotImplementedException();
        }

        private void OnTriggerStay2D(Collider2D other)
        {
            throw new NotImplementedException();
        }

        private void OnCollisionEnter2D(Collision2D other)
        {
            throw new NotImplementedException();
        }

        private void OnCollisionExit2D(Collision2D other)
        {
            throw new NotImplementedException();
        }

        private void OnCollisionStay2D(Collision2D other)
        {
            throw new NotImplementedException();
        }
看看你做了什么?您混淆了函数
OnTriggerEnter2D
,但您正在为
OnCollisionEnter2D
传递参数


因此,请更改:
public void OnTriggerEnter2D(Collision2D-other)
private void OnTriggerEnter2D(collisted-other)

非常感谢!我的错是我没有检查签名。