我是靠谱客的博主 长情棉花糖,这篇文章主要介绍Unity实验代码CreateBullets.csFlightingBullet.csTestVirtualKey.csControlEmptyGameObject.cs,现在分享给大家,希望可以做个参考。

Unity实验代码

  • CreateBullets.cs
  • FlightingBullet.cs
  • TestVirtualKey.cs
  • ControlEmptyGameObject.cs

CreateBullets.cs

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CreateBullets : MonoBehaviour { public GameObject bullet; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { for(int i=0;i<5;i++) { Vector3 position = new Vector3 (Random.Range (-1.0f, 1.0f), Random.Range (3.0f, 5.0f), 19.0f); Instantiate (bullet, position, bullet.transform.rotation); } } } }

FlightingBullet.cs

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System.Collections; using System.Collections.Generic; using UnityEngine; public class FlightingBullet : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { transform.Translate (Vector3.back * Time.deltaTime * Random.Range (10, 30), Space.World); if (transform.position.z < 0) { Destroy (this.gameObject); } } }

TestVirtualKey.cs

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System.Collections; using System.Collections.Generic; using UnityEngine; public class TestVirtualKey : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { this.transform.Translate (Vector3.forward * Input.GetAxis ("Vertical") * 5.0f * Time.deltaTime, Space.World); this.transform.Translate (Vector3.right * Input.GetAxis ("Horizontal") * 5.0f * Time.deltaTime, Space.World); } }

ControlEmptyGameObject.cs

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ControlEmptyGameObject : MonoBehaviour {     public float speed = 10.0f;     public float rotationSpeed = 100.0f;     // Use this for initialization     void Start () {              }          // Update is called once per frame     void Update () {         transform.Rotate (Input.GetAxis ("Horizontal") * Time.deltaTime * rotationSpeed * Vector3.up, Space.Self);         transform.Translate (Input.GetAxis ("Vertical") * Time.deltaTime * speed * Vector3.forward, Space.Self);     } }

最后

以上就是长情棉花糖最近收集整理的关于Unity实验代码CreateBullets.csFlightingBullet.csTestVirtualKey.csControlEmptyGameObject.cs的全部内容,更多相关Unity实验代码CreateBullets内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

相关文章

评论列表共有 0 条评论

立即
投稿
返回
顶部