Unity实现简单太阳系 |
您所在的位置:网站首页 › 真实的太阳系 › Unity实现简单太阳系 |
资源准备
网上的贴图资源较为散乱,此处提供一个太阳系贴图的网站,图片还是相当精美的:https://www.solarsystemscope.com/textures/ 1、保存相应资源并导入成material:
2、特别注意导入太阳material时,为了更逼真,我为其设置了自发光的属性,实现自发光有两种方法。 第一种:https://blog.csdn.net/qq_44148565/article/details/123117751 但是其中光的颜色还需自己调,我尝试过后发现不太自然,于是没有采用。 第二种:只需将太阳material的Shader属性改为Legacy Shaders/Self-Illumin/Diffuse即可,色调比较自然。 下图为前后对比:
但我还想要实现明显照亮其他行星的效果,所以在太阳游戏对象中再增加了一个点光源: 效果还是很明显的:
对于行星,要实现公转、自转以及公转法平面的设置: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Rotate : MonoBehaviour { public GameObject target; //天体旋转的中心 public float gspeed; //公转速度 public float zspeed; //自转速度 public float ry,rz; //通过y轴和z轴调整法平面 // Start is called before the first frame update void Start(){} // Update is called once per frame void Update() { //旋转轴 Vector3 axis = new Vector3(0,ry,rz); //公转 this.transform.RotateAround(target.transform.position, axis, gspeed * Time.deltaTime); //自转 this.transform.Rotate(Vector3.up * zspeed * Time.deltaTime); } }对于太阳,只需实现自转: using System.Collections; using System.Collections.Generic; using UnityEngine; public class sun_rotate : MonoBehaviour { public float speed; // Start is called before the first frame update void Start(){} // Update is called once per frame void Update() { this.transform.Rotate(Vector3.up * speed * Time.deltaTime); } }将脚本Rotate挂载在所有行星上,然后进行相应参数设置。以地球为例:
背景设置 背景素材在文章开头那个网站里也找得到。教程参见:https://segmentfault.com/a/1190000008505014 运行效果
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |