用effects里的particle system做了个火焰,用下面的脚本随机生成:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomPlace : MonoBehaviour
{
public Transform[] SpawnPoints;//存放生成位置
public GameObject prefab;//生成的物体
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);//生成位置数组下标
//随机生成一个数组的下标
Instantiate(prefab, SpawnPoints[Index].position, SpawnPoints[Index].rotation);
//prefab: 生成的物体
//SpawnPoint[Index].position: 生成的物体所在的位置
//SpawnPoint[Index].rotation: 生成物体的角度
}
}
但是却没有反应,但如果绑定一个物体的话,就可以正常生成:
随便问一下,怎么让物体生成在方块的上方而不是中间,非常感谢
这个的话可以试试这个简易的方法,就是建立一个空的游戏物体作为你这些物体的父物体,调整重心到你需要生成粒子效果的位置,然后将游戏脚本挂在在这个空的游戏物体上面。
根据您提供的代码,我发现您需要确保以下几点,以便使 RandomPlace 脚本成功生成 prefab:
如果您的代码符合以上三个条件,您的 RandomPlace 脚本就应该能够生成 prefab 了。如果还是不行,您可以检查 Console 中是否有任何错误或警告信息,以找到问题的根源。
不知道你这个问题是否已经解决, 如果还没有解决的话: