生成多行砖块
|
子弹发射
- using UnityEngine;
- using System.Collections;
- public class Gun : MonoBehaviour {
- // 发射子弹的代码
- public GameObject gun;
- public GameObject bullet;
- void Start () {
-
- }
-
- // Update is called once per frame
-
- public float firetime = 0.3f;
- //子弹发射所用的时间
- public float nexttime = 0.0f;
- //间隔时间
- void Update () {
- transform .Translate (new Vector3 (Input .GetAxis ("Horizontal"),0,Input .GetAxis ("Vertical")));
- //枪移动
- if (Input.GetButton("Fire1") && Time.time > nexttime)
- {
- nexttime = Time.time + firetime;
- GameObject t = Instantiate(bullet, gun.transform.position, Quaternion.identity) as GameObject;
- //克隆子弹
- t.rigidbody.AddForce(0, 0, 2000);
- //给子弹加个力
- }
- }
- }