解释
相机前进,流星后退
时刻在相机前面复制流星,然后流星向后移动。
图示
空物体:
相机:
呈现效果:
代码
空物体:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FuZhi : MonoBehaviour {
public float RandomX = 0.01f;
public float RandomY = 0.1f;
public float RandomZ = 3f;
public float RandomVal = 1f;
public int DestoryTime = 1;
public GameObject prefab1;
public GameObject prefabCamera;
Vector3 pos ;
Vector3 pos1;
void Start()
{
pos = prefabCamera.transform.position;
}
void FixedUpdate()
{
pos = prefabCamera.transform.position;
}
void Update()
{
GameObject obj1 = Instantiate(prefab1) as GameObject;
pos1.x = pos.x + Random.Range (RandomX, RandomX+RandomVal);
pos1.y = pos.y + Random.Range (RandomY, RandomY+RandomVal);
pos1.z = pos.z + Random.Range (RandomZ, RandomZ+RandomVal);
obj1.transform.position = pos1;
Destroy (obj1, DestoryTime);
}
}
相机:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ZiMove : MonoBehaviour {
public float MoveSpeed = 10;
// Update is called once per frame
void FixedUpdate () {
transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime, Space.World);
}
}