
场景搭建:     构建场景:用于场景的调转 
 场景渲染:用于重新开始游戏后,场景亮度不均衡问题:  先取消对Auto Generate的勾选 然后点击Generate Lighting  标签的设置:  
部分代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
Rigidbody r;
public float speed;
public GameObject bullets;
public Transform bullctPos;
void Start() {
r = GetComponent<Rigidbody>();
}
void Update() {
Fire();
Fire2();
float h = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
float v = Input.GetAxis("Vertical") * Time.deltaTime * speed;
Vector3 pos = new Vector3(h, 0, v);
r.velocity = pos;
}
void Fire() {
if (Input.GetButtonDown("Fire1"))
{
Instantiate(bullets,bullctPos.position,Quaternion.identity);
}
}
void Fire2()
{
if (Input.GetKeyDown(KeyCode.F))
{
if (GameObject.FindWithTag("Enemy1"))
{
GameObject a= GameObject.FindWithTag("Enemy1");
Destroy(a.gameObject);
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletsMove : MonoBehaviour {
Rigidbody r;
public float speed;
public GameObject bullet;
void Start () {
r = GetComponent<Rigidbody>();
StartCoroutine("Span");
}
void Update () {
r.velocity = Vector3.forward * speed * 3;
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Enemy"))
{
Destroy(other.gameObject);
}
else
{
Span();
}
}
IEnumerator Span()
{
yield return new WaitForSeconds(5f);
Destroy(bullet);
}
}
整个项目以打包上传,有需要的朋友可以自行下载
|