为了账号安全,请及时绑定邮箱和手机立即绑定

unity OnTriggerEnter

unity OnTriggerEnter

C#
收到一只叮咚 2021-06-25 17:57:45
我希望我的 Player 与对象胶囊发生碰撞。这个动作应该摧毁胶囊并为玩家增加一个 10 的速度值。但是这段代码不起作用:public class PlayerController : MonoBehaviour {public KeyCode moveL;public KeyCode moveR;public float horizontal = 0;public int laneNum = 2;public string controllocked = "n";public float speed;void Update (){    GetComponent<Rigidbody>().velocity = new Vector3(horizontal, GM.verticalVelocity, speed);    if ((Input.GetKeyDown(moveL)) && (laneNum > 1) && (controllocked == "n"))    {        horizontal = -2;        StartCoroutine(StopSlide());        laneNum = laneNum - 1;        controllocked = "y";    }    else if ((Input.GetKeyDown(moveR)) && (laneNum < 3) && (controllocked =="n"))    {        horizontal = 2;        laneNum = laneNum + 1;        StartCoroutine(StopSlide());        controllocked = "y";    }}void OnCollisionEnter(Collision other){    if(other.gameObject.tag == "lethal")    {        Destroy(gameObject);    }    if (other.gameObject.name == "Capsule")    {        Destroy(other.gameObject);        speed = 10;       }}IEnumerator StopSlide(){    yield return new WaitForSeconds(.5f);    horizontal = 0;    controllocked = "n";}到目前为止我尝试过的是speed += 10,speed++两者都不起作用。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 125 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信