Unity学习记录——空间与运动

Unity学习记录——空间与运动

前言


​ 本文是中山大学软件工程学院2020级3d游戏编程与设计的作业3

编程题


1. 模拟太阳系

​ 首先向unity中Assets添加所找的贴图素材Solar Textures | Solar System Scope

在这里插入图片描述

​ 再在Scene中建立十个Sphere以表示八个行星和月球太阳

在这里插入图片描述

​ 建立完成十个SPhere之后,将对应的星球贴图拖动到星球之上。此时Assets之中会生成Materials文件夹,里面为十个星球的材质。

在这里插入图片描述

​ 完成简单的贴图以及位置排序之后各个行星排列如下所示

在这里插入图片描述

​ 对模拟太阳系进行进一步优化,如下

​ 删除原先默认建立的光源,在太阳上建立一个点光源,如下

在这里插入图片描述

​ 再在太阳的材质处进行修改,添加Emission,使之发光

在这里插入图片描述

​ 此时在Assets区建立C#代码,命名为MoveBehavior,用于进行八大行星和月球的自转以及公转。

​ 代码如下:

public class MoveBehaviourScript : MonoBehaviour
{
    // 公转中心
    public Transform center;
    // 公转速度
    public float around_speed;
    // 自转速度
    public float self_speed;
    // 旋转所绕的轴
    public float x = 0, y, z;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Vector3 axis = new Vector3(x, y, z);
        // 自转
        this.transform.Rotate(Vector3.up * self_speed * Time.deltaTime);
        // 公转
        this.transform.RotateAround(center.position, axis, around_speed * Time.deltaTime);
    }
}

​ 将各个代码拖入进行自转与公转的行星,设置旋转中心以及速度等数值

​ 给各个行星对象设置拖尾渲染器,使得行星运行效果更为明显

在这里插入图片描述

​ 再将摄像机的背景色设置为黑色

在这里插入图片描述

运行效果如下:

gif太大无法上传至csdn,可于gitee查看,链接如下:
hw3/img/P9.gif · XiaoChen04_3/3D_Computer_Game_Programming

2.牧师与魔鬼
  • 游戏规则如下:

​ Priests and Devils is a puzzle game in which you will help the Priests and Devils to cross the river within the time limit. There are 3 priests and 3 devils at one side of the river. They all want to get to the other side of this river, but there is only one boat and this boat can only carry two persons each time. And there must be one person steering the boat from one side to the other side. In the flash game, you can click on them to move them and click the go button to move the boat to the other direction. If the priests are out numbered by the devils on either side of the river, they get killed and,the game is ovet You can ry it in many→ ways. Keep all priests alive! Good luck!

  • 游戏中提及的事物(Object)包括:牧师,魔鬼,船,河,陆地

  • 玩家动作表如下

动作 条件 结果
点击角色(牧师或魔鬼) 角色与船同岸;角色在船上 角色上岸
点击角色(牧师或魔鬼) 角色与船同岸;角色在岸上 角色上船
点击船 船上存在一或两个角色 船开到对岸
  • MCV架构以及其介绍

    • M是Model:代表游戏中所有的游戏对象,它们受各自的Controller控制。Model是游戏中存在的实体。
    • V是View:代表游戏呈现出的界面。主要包括GUI和Click两部分,GUI负责展示游戏结果,Click负责处理用户点击事件。
    • C是Controller:代表游戏中的控制器,分为FitstController(场景控制器)和SSDir
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值