1. 游戏对象运动的本质是什么
简单来说就是游戏对象跟随每一帧的变化,空间上发生变化。这里的空间变化包括了游
戏对象的transform组件中的position和rotation两个属性,前者是绝对或者相对
位置的改变,后者是所处位置的角度的旋转变化。
2. 使用三种以上的方法实现物体的抛物线运动
抛物线运动的本质就是改变物体的position属性,以下三种方法都是改变物体position的,只是实现不同
方法一:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour {
private float speed = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position += Vector3.left * 5.0f ;
transform.position += Vector3.down * speed * Time.deltaTime;
speed += 9.8f * Time.deltaTime;
}
}
方法二
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour {
private float speed = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position += new Vector3(Time.deltaTime * 5.0f, Time.deltaTime * speed, 0);
speed -= Time.deltaTime * 9.8f;
}
}
方法三:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour {
private float speed = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate(new Vector3(Time.deltaTime * 5.0f, Time.deltaTime * speed, 0));
speed -= Time.deltaTime * 9.8f;
}
}
写一个程序,实现一个完整的太阳系, 其他星球围绕太阳的转速必须不一样,且不在一个法平面上。
添加GameObject
给每个物体添加不同的材料(简单点的话就是直接把图片拖到GameObject上)
给行星添加公转行为(orgin为sun)(月球的公转行为也一样,orgin为earth)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rotate : MonoBehaviour {
public Transform orgin;
public float speed;
float x, z;
// Use this for initialization
void Start () {
//使每个行星的法平面不同,不过每次启动行星的法平面都会发生变化,最好可以固定下来吧
x = Random.Range(0.1f, 0.3f);
z = Random.Range(0.1f, 0.3f);
}
// Update is called once per frame
void Update () {
Vector3 axios = new Vector3(x, 1, z);
this.transform.RotateAround(orgin.position, axios, speed * Time.deltaTime);
}
}
给太阳、行星和月球添加自转行为
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class selfRotate : MonoBehaviour {
public float speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.transform.RotateAround(this.transform.position, Vector3.up, speed * Time.deltaTime);
}
}
添加背景
*创建skybox的Materials,将Shader设为panoramic,将宇宙的图片拖入Spherial中
将windows下的lighting的skybox Material设为刚刚创建的Matertial
然后特别难看的太阳系就出来了