我是靠谱客的博主 长情棉花糖,最近开发中收集的这篇文章主要介绍Unity实验代码CreateBullets.csFlightingBullet.csTestVirtualKey.csControlEmptyGameObject.cs,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
Unity实验代码
- CreateBullets.cs
- FlightingBullet.cs
- TestVirtualKey.cs
- ControlEmptyGameObject.cs
CreateBullets.cs
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
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
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
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.csFlightingBullet.csTestVirtualKey.csControlEmptyGameObject.cs所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复