unity飞机大战

实验目的

1. 掌握一个游戏/VR项目的制作流程。

2. 掌握引入资源、创建新场景的方法。

3. 掌握项目内场景搭建、打光的方法。

4. 掌握物体限范围移动、预制体创建的方法。

实验内容及步骤

1. 在Unity中打开新的场景,在Hierarchy中增加主角模型player,并设置该模型对象的刚体、碰撞体、tag等组件。

2 .搭建场景的背景,设置相机的位置,并让场景光照正常打光。

  1. 添加playercontroller脚本,并完善代码,让飞机player可以在正确范围内根据上下左右输入而移动。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class player : MonoBehaviour
{
    public float speed = 10f;
    public float fireRate = 0.25f;
    public Boundary bound;
    public GameObject bolt;
    public Transform boltPos;
    public AudioClip fireAudio;

    private Rigidbody m_rigidbody;
    private float fireTimer = 0f;

    public void Destory()
    {

    }
    public void Awake()
    {
        
    }
    public void Start()
    {
        bound = new Boundary();
        m_rigidbody = GetComponent<Rigidbody>();
    }

    public void FixedUpdate()
    {
        //获取你按WASD或上下左右的情况
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        //如何让物体跟着按钮移动
        Vector3 move = new Vector3(h, 0f, v);
        m_rigidbody.velocity = speed * move;
        
        //移动在某个范围内
        Vector3 pos = new Vector3(Mathf.Clamp(m_rigidbody.position.x, bound.xMin, bound.xMax), 0f, Mathf.Clamp(m_rigidbody.position.z, bound.zMin, bound.zMax));
        transform.position = pos;
    }
        // Update is called once per frame
    private void Update()
    {
        if (bolt != null && boltPos != null) {
            if (Input.GetMouseButton(0))
            {
                if (fireTimer >= fireRate)
                {
                    Instantiate(bolt, boltPos.position, boltPos.rotation);
                    fireTimer = 0f;
                    if (fireAudio!= null)
                    {
                        GetComponent<AudioSource>().PlayOneShot(fireAudio);
                    }
                }
                fireTimer += Time.deltaTime;
            }
        }
    }
public class Boundary
    {
        public float xMin = -6f;
        public float xMax = 6f;
        public float zMin = -6f;
        public float zMax = 16f;
    }
   
}
4. 制作子弹预制体,并添加move脚本,使子弹可以随输入正确生成在飞机前端。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bolt : MonoBehaviour
{
    public float speed = 20f;
    private Rigidbody m_rigidbody;
    // Start is called before the first frame update
    private void Start()
    {
        m_rigidbody = GetComponent<Rigidbody>();
        m_rigidbody.velocity = transform.forward * speed;
    }

    
}

实验总结

1、收获

  1. 通过制作飞机大战游戏,你可以深入学习Unity游戏引擎的使用,包括场景搭建、角色创建、动画设计、物理效果实现等。这有助于提升你的游戏开发技能,为未来的游戏开发打下基础。
  2. Unity飞机大战的制作是一个富有挑战性和收获性的过程,不仅可以提升你的专业技能,还可以培养你的综合素质。

存在的问题

  1. 性能问题是一个常见的挑战。游戏在运行时可能会出现卡顿、延迟或帧率下降的情况,这通常是由于资源加载不当、代码优化不足或场景过于复杂造成的。为了解决这些问题,你可以尝试优化游戏资源,减少不必要的渲染和计算,以及合理管理内存使用。
  2. 游戏平衡性也是一个重要的问题。如果飞机的性能设置不合理,或者敌人难度过高或过低,都可能让玩家感到无趣或挫败。你需要根据玩家的反馈和测试数据来调整游戏平衡性,确保游戏具有挑战性和趣味性。
作者声明:该内容是学习内容经供参考。
  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小蕊。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值