亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 175 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號