首先,这里子弹要模拟的相似的话,用2D刚体比较好,会有重力,自由落体运动。

 

using UnityEngine;
using System.Collections;

public class gun : MonoBehaviour {

	public Rigidbody2D rocket;
	public float speed;
	// Use this for initialization

	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if(Input.GetKey(KeyCode.K)){
不断的实例化子弹刚体,并让其向前运动。 Rigidbody2D bullet = Instantiate(rocket,transform.position,Quaternion.Euler(new Vector3(0,0,0))) as Rigidbody2D; //使刚体运动 Y方向为0 bullet.velocity = new Vector2(speed,0); } } }

  效果如图:

U3D 实现子弹发射效果

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2021-12-09
  • 2021-12-23
  • 2022-12-23
相关资源
相似解决方案