Physics.ContactEvent += Physics_ContactEvent;
public class Weapon : MonoBehaviour
{
int _currentAmmo;
[SerializeField]int _maxAmmo;
[SerializeField] UIDrawer _playerUI;
private void Start()
{
_currentAmmo=_maxAmmo;
}
private void Update()
{
if (Input.GetMouseButtonDown(0)) TryFire();
}
void TryFire()
{
//Тут какая то логика на проверку можем ли мы стрелять
Fire();
}
void Fire()
{
//тут типо логика стрельбы
_currentAmmo--;
_playerUI.SetNewAmmo(_currentAmmo);
}
}
public class UIDrawer : MonoBehaviour
{
[SerializeField] private Text _ammoText;
public void SetNewAmmo(int a)
{
_ammoText.text = a.ToString();
}
}
audioSource.clip = fireAudio;
audioSource.Play();
замени на
audioSource.PlayOneShot(fireAudio, 1f);
void MovementLogic()
{
_controller.Move(_moveDir * _playerSpeed * Time.deltaTime +_playerVelocity * Time.deltaTime );
}
void Gravity()
{
if (_groundedPlayer && _playerVelocity.y < 0){
_playerVelocity.y = 0f;
}
_playerVelocity.y += _gravityValue * Time.deltaTime;
}
void MovementLogic()
{
_controller.Move(_moveDir * _playerSpeed * Time.deltaTime +Vector3.up*_playerVelocity * Time.deltaTime );
}
movePlayer : MonoBehaviour
void movementLogic()
if (Input.GetButtonDown("Jump") && _groundedPlayer)
{
_playerVelocity.y += Mathf.Sqrt(_jumpHeight * -3.0f * _gravityValue);
}
_controller.Move(_moveDir * _playerSpeed);
_controller.Move(_moveDir * _playerSpeed);
****
_controller.Move(_playerVelocity * Time.deltaTime);
void Update()
{
_moveDir = tranform.forward * Input.GetAxis("Horizontal")+tranform.right * Input.GetAxis("Vertical");
}
void FixedUpdate()
{
rb.AddForce(_moveDir*_moveSpeed, ForceMode.VelocityChange);
}
using UnityEngine;
public class PlayerRotating: MonoBehaviour
{
float _rotationgSpeed;
float _minPitch=-89f;
float _maxPitch=89f;
[SerializeField]Transform _objYaw; // mainObj
[SerializeField]Transform _objPitch; //camObj
float _yaw;
float _pitch;
public void Update()
{
float x = Input.GetAxis("Mouse X");
float y = Input.GetAxis("Mouse Y");
RotateUpdate(x,y);
}
public void RotateUpdate(float x,float y)
{
_yaw += x*_rotationgSpeed*Time.deltaTime;
_pitch-=y*_rotationgSpeed*Time.deltaTime;
_objYaw.transform.rotation = Quaternion.Euler(0,Clamper(_yaw),0);
_objPitch.transform.localRotation=Quaternion.Euler(Clamper(_pitch,_minPitch,_maxPitch),0,0);
}
float Clamper(float angle,float min=-360f,float max=360f)
{
if (angle < -360f) angle += 360f;
if (angle > 360f) angle -= 360f;
if(min!=-360f||max!=360f) angle = Mathf.Clamp(angle, min, max);
return angle;
}
}
https://docs.unity3d.com/6000.0/Documentation/Manu...