Unity:在特定角度射出炮彈

views

這是在Rage of Civilian新開發但未被採用的武器系統功能 O_Q 但可能可以用在其他的物理小遊戲上 所以趕快寫下來供日後參考

設定注意事項

相關程式碼

var weaponInitialSpeed:int=10000;
var bulletObject: GameObject;
private var hitPt:Vector3; 
private var hit : RaycastHit;

function Update () 
{
  var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  if (Input.GetMouseButtonDown (0))
  {
    if (Physics.Raycast (ray, hit, 500.0f)) 
    {
      if (hit.collider.tag == "ground")
      {
        var bullet = Instantiate(bulletObject, Vector3(0,1.5,-12), transform.rotation);
        bullet.rigidbody.AddForce( Vector3(0,0.5,0.5) * weaponInitialSpeed);
      }
                }
        }
}
									

影片教學

This entry was posted in Unity小技巧, 武器系統 by Mr.M. Bookmark the permalink.


Leave a Reply

Your email address will not be published. Required fields are marked *