float fps=1/Time.deltaTime;
using UnityEngine;
public class ParentUsing : MonoBehaviour
{
GameObject _targetGO;
bool UIVision;
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && _targetGO != null)
{
ParentSet(_targetGO);
}
}
void ParentSet(GameObject newParentCursor)
{
gameObject.transform.parent = newParentCursor.transform;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Cursor")
{
UIVision = true;
_targetGO= other.gameObject;
}
}
private void OnTriggerExit(Collider other)
{
if(_targetGO==other.gameObject)_targetGO = null;
}
}
using UnityEngine;
using UnityEngine.AI;
public class DebugAI : MonoBehaviour
{
NavMeshAgent _agent;
void Start()
{
_agent = GetComponent<NavMeshAgent>();
}
private void OnDrawGizmos()
{
NavMeshPath path = _agent.path;
Vector3 nowpoint = transform.position;
foreach (Vector3 point in path.corners)
{
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(point, 0.15f);
Gizmos.color= Color.green;
Gizmos.DrawLine(nowpoint, point);
nowpoint = point;
}
}
}
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class Tester : MonoBehaviour
{
[SerializeField] List<Transform> _allPoint=new List<Transform>();
Transform _targetPos;
[SerializeField] Transform _playerPos;
[SerializeField] float _playerTargetDis;
[SerializeField] float _stopDistans;
[SerializeField] float _speed;
bool _isToPlayer;
private void Start()
{
SetAllPoint();
_targetPos = SelectRandom();
}
void SetAllPoint()
{
foreach (GameObject t in GameObject.FindGameObjectsWithTag("Point"))
{
_allPoint.Add(t.transform);
}
}
Transform SelectRandom()
{
int rand = Random.Range(0, (_allPoint.Count));
Debug.Log(rand);
return _allPoint[rand];
}
private void Update()
{
if (_isToPlayer) MoveToPlayer();
else MoveToPoint();
}
private void FixedUpdate()
{
_isToPlayer = SeePlayer();
}
void MoveToPoint()
{
transform.position = Vector3.MoveTowards(transform.position, _targetPos.position, _speed * Time.deltaTime); //заменить мб движение по нашмешу
if(Vector3.Distance(transform.position, _targetPos.position) < _stopDistans) _targetPos = SelectRandom();
}
void MoveToPlayer()
{
transform.position = Vector3.MoveTowards(transform.position, _playerPos.position, _speed * Time.deltaTime);
}
bool SeePlayer() //тут это от проекта зависит я сделал от дальности без поля зрения и тд
{
if (Vector3.Distance(transform.position, _playerPos.position) > _playerTargetDis) return false;
return true;
}
}
using UnityEngine;
public class Item : ScriptableObject
{
public enum ObjType
{
HeavyArmor, LightArmor, Swords, Stuffs
}
public int _id;
public string _name;
public ObjType _Objtype;
public Sprite[] _sprites;
public Sprite icon;
}
using UnityEngine;
[CreateAssetMenu]
public class Weapon : Item
{
public float _damage;
public float _speedAttack;
}
using System.Collections.Generic;
using UnityEngine;
using static Item;
public class ItemHolder : MonoBehaviour
{
[SerializeField]List<Item> _allITemList = new List<Item>();
[SerializeField]List<Item> _sword=new List<Item>();
private void Awake()
{
CreateNewList(_sword, ObjType.Swords,false);
}
void CreateNewList(List<Item>newlist,ObjType type,bool delete) // как пример создания листа
{
foreach (var item in _allITemList)
{
if (item._Objtype == type)
{
newlist.Add(item);
if(delete)_allITemList.Remove(item);
}
}
}
}
if (Input.GetKeyDown(KeyCode.Z) && !isPressed)
{
target = turretParent;
distance = dist;
heightPosition = height;
isPressed = true;
}
if (Input.GetKeyDown(KeyCode.Z) && isPressed)
{
target = turretBarrel;
distance = 0f;
heightPosition = 0f;
isPressed = false;
}
using UnityEngine;
public class Rotate : MonoBehaviour
{
float _currentSpeed;
float _targetSpeed;
[SerializeField] float _speedRotate;
const float c_acceleration = 20f;
const float c_di_acceleration = 10f;
float _acceleration;
private void Update()
{
_targetSpeed = Input.GetAxis("Mouse Y")*_speedRotate;
_acceleration = _targetSpeed != 0 ? c_acceleration : c_di_acceleration;
_currentSpeed = Mathf.MoveTowards(_currentSpeed, _targetSpeed, _acceleration * Time.deltaTime);
}
}