[SerializeField] float _minRand = 87f;
[SerializeField] float _maxRand = 130f;
[SerializeField] GameObject _car;
[SerializeField] float _checkSphereRad = 2f;
[SerializeField] LayerMask _carMask;
void Start()
{
StartCoroutine(Spawner());
}
IEnumerator Spawner()
{
while (true)
{
float rand = Random.Range(_minRand, _maxRand);
Vector3 pos = new Vector3(-5.5f, 0.5f, rand);
if (Physics.CheckSphere(pos, _checkSphereRad, _carMask)) continue;
GameObject newCar = Instantiate(_car, pos, Quaternion.identity);
Destroy(newCar, 20f);
yield return new WaitForSeconds(2.8f);
}
}
}
[SerializeField] Transform _target; //<= обьект для слежения
[SerializeField] float _yOffset=1f;
private void LateUpdate()
{
transform.position = new Vector3(_target.position.x, _yOffset, _target.position.z);
}
using UnityEngine;
[System.Serializable]
public class Upgrade
{
[SerializeField] private string _typeName;
[SerializeField] private int _price;
[SerializeField] private float _damage;
}
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class UpgrageList : MonoBehaviour
{
string _name="Tower";
[SerializeField] List<Upgrade>_upgrades;
[ContextMenu("Save")]
public void SaveState()
{
var json = JsonUtility.ToJson(this);
File.WriteAllText(Application.persistentDataPath + $"{_name}.so", json);
Debug.Log(Application.persistentDataPath);
}
[ContextMenu("Load")]
public void LoadState()
{
var json = File.ReadAllText(Application.persistentDataPath + $"{_name}.so");
JsonUtility.FromJsonOverwrite(json, this);
}
}
{"_upgrades":[{"_typeName":"Fire","_price":5,"_damage":"30"},{"_typeName":"Ice","_price":5,"_damage":"40"},{"_typeName":"Earth","_price":2,"_damage":"10"}]}
Ну могу предложить вызвать профайлер(ctrl+7) и там посмотреть играют ли файлы