首先先按照【建议做】里的步骤做一遍,了解设计一个游戏所需要的框架结构以及核心代码。(具体过程【建议做】里便有了,代码的话文章中也给了,就不再赘述)
游戏对象运动的本质是游戏对象的空间属性(位置和旋转角)随着每一帧的变化。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Parabola1 : MonoBehaviour
{public float xspeed = 1;public float yspeed = 1;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){yspeed += 1*Time.ansform.position += Vector3.right*Time.deltaTime*ansform.position += Vector3.down*Time.deltaTime*yspeed;}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Parabola2 : MonoBehaviour
{public float xspeed = 1;public float yspeed = 1;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){yspeed += 2*Time.ansform.position += new Vector3(xspeed*Time.deltaTime, -yspeed*Time.deltaTime, 0);}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Parabola3 : MonoBehaviour
{public float xspeed = 1;public float yspeed = 1;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){yspeed += 2*Time.deltaTime;Vector3 v = new Vector3(xspeed*Time.deltaTime, -yspeed*Time.deltaTime, 0);ansform.Translate(v);}
}
完整的太阳系一共要求有太阳以及它的八大行星,其他的天体都不在考虑范围内。
阅读游戏脚本:
Priests and Devils
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 over. You can try it in many > ways. Keep all priests alive! Good luck!
程序需要满足的要求:
游戏中提及的事物有:牧师、魔鬼、船、河以及两个河岸
动作 | 条件 |
---|---|
点击船 | 船在岸且船上有1~2人 |
牧师上船 | 牧师与船在同岸且船上有空位 |
魔鬼上船 | 魔鬼与床同岸且船上有空位 |
牧师下船 | 船靠岸且牧师在船上 |
魔鬼下船 | 船靠岸且魔鬼在船上 |
用白色球体代表牧师,黑色柱体代表魔鬼,绿色柱体代表河岸,蓝色柱体代表河流,棕色柱体代表船。
public void LoadResources(){GameObject river = Instantiate (Resources.Load ("Prefabs/river", typeof(GameObject)), river_pos, Quaternion.identity, null) as GameObject;river.name = "river";fromSide = new SideController("from");toSide = new SideController("to");boat = new BoatController();loadCharacter();}
整个游戏的代码以及其他游戏资源都放在了gitee仓库中了。(传送门)
在设计MVC架构中的控制器部分时,一开始我将控制器拆分成FirstController.cs、BoatController.cs、SideController.cs、MyCharacterController.cs、moveable.cs等文件,但是在最后运行出现了以下问题
上网查询说是不同文件的游戏对象加载时间不一样,没有放在同一个代码文件的话可能会出现一个类加载后另一个类还没加载的情况。
**解决方法:**将除了FIrstController.cs文件外的所有内容整合到同一个文件中(basecode.cs),并将这些代码定义为命名空间,可以被其他文件所引用。(namespace mygame{})
本文发布于:2024-01-27 18:57:08,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063530262019.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |