Код: Выделить всё
Instantiate(spawnPrefab, new Vector3(player.position.x, player.position.y, player.position.z), Quaternion.identity);
Вот весь скрипт.
Код: Выделить всё
using UnityEngine;
public class SpawnChunk : MonoBehaviour
{
public GameObject spawnPrefab;
public Transform player;
private static SpawnChunk instance;
private float spawnCooldown = 1.5f;
private float lastSpawnTime = -1f;
void Update ()
{
if (Time.time >= lastSpawnTime + spawnCooldown && Input.GetKeyDown(KeyCode.C))
{
DuplicateChunk();
lastSpawnTime = Time.time;
}
}
void Awake ()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
}
instance = this;
DontDestroyOnLoad(this.gameObject);
}
public void DuplicateChunk ()
{
if (spawnPrefab != null && player != null && Input.GetKeyDown(KeyCode.C))
{
Debug.Log("unity why do you have to make this so hard for me");
Instantiate(spawnPrefab, new Vector3(player.position.x, player.position.y, player.position.z), Quaternion.identity);
}
else
{
if (spawnPrefab == null) Debug.LogError("****Spawn Prefab is null****");
if (player == null)
{
Debug.LogError("****Player is null****");
player = GameObject.FindGameObjectWithTag("Player").transform;
}
}
}
void LateUpdate ()
{
DuplicateChunk();
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... t-position
Мобильная версия