void MoveToPlayer()
{
transform.position = Vector3.MoveTowards(transform.position, _playerPos.position, _speed * Time.deltaTime);
}
void MoveToPlayer()
{
agent.SetDestination(_playerPos.position);
}
using UnityEngine;
public class Player : MonoBehaviour
{
[Header("PlayerAnker")]
[SerializeField] Transform _armorPos;
[SerializeField] Transform _weaponPos;
[SerializeField] Transform _helmetPos;
ItemHolder _ItemBase;
[Header("inventory")]
Item _helmetItem;
Item _weaponItem;
Item _armorItem;
private void Start()
{
_ItemBase = GameObject.FindGameObjectWithTag("GameMaster").GetComponent<ItemHolder>();
NewSword();
}
void NewSword()
{
_weaponItem = _ItemBase._allITemList[0]; //<= ну условно у меня там есть метод для получение нужного меча
EquipItem(_weaponItem, _weaponPos);
}
void EquipItem(Item item,Transform pos)
{
item.ReOpenItem(pos);
}
}
_sprites:
- {fileID: 10913, guid: 0000000000000000f000000000000000, type: 0}
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;
public virtual void ReOpenItem(Transform pos)
{
GameObject openObj =new GameObject();
openObj.transform.position = pos.position;
openObj.transform.name = _name;
for (int i=0; i< _sprites.Length; i++)
{
GameObject sonObj = new GameObject();
sonObj.transform.SetParent(openObj.transform);
sonObj.transform.localPosition = Vector2.zero; //?
sonObj.AddComponent<SpriteRenderer>().sprite = _sprites[i];
sonObj.transform.name = "Sprite " + (i + 1);
}
}
}
using UnityEngine;
using UnityEngine.UI;
public class Plus : MonoBehaviour
{
Text _text;
private void OnEnable()
{
_text = GetComponent<Text>();
}
private void Start()
{
_text.text = "Testing";
}
}
using UnityEngine;
public class Mover : MonoBehaviour
{
Rigidbody _rb;
float _currentSpeed;
[SerializeField] float _walkSpeed=5f;
[SerializeField] float _runSpeed=7f;
[SerializeField] float _sprintSpeed=10f;
Vector2 _inputVec2;
Vector3 _moveVecto3;
bool _sprint;
bool _superStrint;
bool _lastUpdateSuperPos;
float _currentSuperSprintTime;
float _superSprimtTime = 1f;
Animator _anim;
private void Start()
{
_rb = GetComponent<Rigidbody>();
_anim = GetComponent<Animator>();
}
private void Update()
{
InputRead();
SpeedControll();
AnimUpdate();
}
void InputRead()
{
_sprint=Input.GetKey(KeyCode.LeftShift);
_superStrint =Input.GetKey(KeyCode.LeftAlt);
if (_superStrint && !_lastUpdateSuperPos) _currentSuperSprintTime = _superSprimtTime;
_inputVec2.Set(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"));
_lastUpdateSuperPos = _superStrint;
}
void AnimUpdate()
{
_anim.SetFloat("MoveFront",_inputVec2.x);
_anim.SetFloat("MoveSIde", _inputVec2.y);
if (IsMove())
{
if (_inputVec2.sqrMagnitude > 1f) _inputVec2.Normalize();
}
_anim.SetFloat("MovePower", _currentSpeed);
}
void SpeedControll()
{
_currentSpeed = _sprint ? _sprintSpeed : _walkSpeed;
if (_superStrint && !(_currentSuperSprintTime > 0))
{
_currentSpeed = _sprintSpeed;
_currentSuperSprintTime -= Time.deltaTime;
}
}
private void FixedUpdate()
{
_moveVecto3.Set(_inputVec2.x, 0, _inputVec2.y);
_rb.MovePosition(_rb.position+_moveVecto3 * Time.fixedDeltaTime * _currentSpeed);
}
bool IsMove()
{
return _inputVec2.sqrMagnitude != 0;
}
}