如图是已经显示了用粒子效果做的火焰,如何选中火焰并显示距离呢?如果要添加脚本,是要新建一个脚本还是在生成火焰的脚本上修改呢?
这是火焰生成脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomPlace : MonoBehaviour
{
public Transform[] SpawnPoints;//存放生成位置
public GameObject prefab;//生成的物体
public float heightOffset;
public float spawnTime = 3f;//多长时间后调用
public float nextSpawnTime = 2f;//下一个物体生成的时间
// Start is called before the first frame update
void Start()
{
InvokeRepeating("SpawnPrefab", spawnTime, nextSpawnTime);
//"SpawnPrefabs" : 调用的方法名称
//spawnTime: 多长时间后调用
//nextSpawnTime: 下一个物体生成的时间
}
private void SpawnPrefab()
{
int Index = Random.Range(0, SpawnPoints.Length);//生成位置数组下标
Vector3 spawnPosition = SpawnPoints[Index].position + new Vector3(0f, heightOffset, 0f);
Instantiate(prefab, spawnPosition, SpawnPoints[Index].rotation);
//prefab: 生成的物体
//SpawnPoint[Index].position: 生成的物体所在的位置
//SpawnPoint[Index].rotation: 生成物体的角度
}