欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity實現(xiàn)桌面反彈的示例代碼

 更新時間:2021年05月30日 11:02:52   作者:Hello Bug.  
反彈球是小時候都玩過的網(wǎng)頁小游戲,但是很多人都不知道怎樣實現(xiàn),本文就來介紹一下Unity實現(xiàn)桌面反彈的示例代碼,感興趣的可以了解一下

一:演示視頻

二:代碼實現(xiàn)

using UnityEngine;
 
public class Ball : MonoBehaviour
{
    private Rigidbody rigid;
 
    private Vector3 lastDir;
 
    public float speed = 30;
 
    private void Awake()
    {
        rigid = GetComponent<Rigidbody>();
 
        rigid.velocity = new Vector3(1, 0, 1) * speed;
    }
 
    private void LateUpdate()
    {
        lastDir = rigid.velocity;
    }
 
    private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "Wall")
        {
            Vector3 reflexAngle = Vector3.Reflect(lastDir, other.contacts[0].normal);
            rigid.velocity = reflexAngle.normalized * lastDir.magnitude;
        }
    }
}

也可以添加

創(chuàng)建物理材質(zhì)

修改值就可以發(fā)生反彈碰撞了

到此這篇關于Unity實現(xiàn)桌面反彈的示例代碼的文章就介紹到這了,更多相關Unity 反彈內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論