if (rb.velocity.y < 0f && !onGround)
{
animator.SetBool("isFall", true);
}
if (rb.velocity.y == 0) // вот это вот условие
{
animator.SetBool("isFall", false);
}
animator.SetBool("isFall", !onGround);
void Jump() {
if (Input.GetKeyDown(KeyCode.Space) && onGround && !jumpLock) {
rb.velocity = new Vector2(rb.velocity.x, 0);
rb.AddForce(new Vector2(0f, jumpForce));
}
}
void Jump() {
if (Input.GetKeyDown(KeyCode.Space) && onGround && !jumpLock) {
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}
public int healthCurrent;
public void OnHealthChanged(int healthDelta)
healthCurrent -= healthDelta;
// update health bar
if (healthCurrent <= 0) {
// death
}
}
public int healthCurrent;
public void OnHealthChanged(int healthDelta)
if (healthCurrent > 0) {
healthCurrent -= healthDelta;
// update health bar
if (healthCurrent < 0) {
// death
}
}
}
public int healthCurrent;
public int healthMaximum;
public void OnHealthChanged(int healthDelta)
healthCurrent = Mathf.Clamp(healthCurrent - healthDelta, 0, healthMaximum);
// update health bar
if (healthCurrent == 0) {
// death
}
}
public void HideCursor() {
#if UNITY_EDITOR
// hide & lock using Cursor class
#else
Cursor.lockState = CursorLockMode.Locked;
#endif
}
public class PlayerController : MonoBehaviour {
// ...
private void Update() {
float xInput = Input.GetAxisRaw("Horizontal");
if (xInput != 0)
transform.localEulerAngles = new Vector3(0, xInput > 0 ? 0 : 180, 0);
// ...
}
// ...
}
using Photon.Pun;
using UnityEngine;
public class FixAudioListener : MonoBehaviour {
// заполнить ссылки в инспекторе до старта игры
public AudioListener listener;
public PhotonView photonView;
private void Start() {
if (!photonView.IsMine)
Destroy(listener); // удалить компоненту с камеры
}
}
using Photon.Pun;
using UnityEngine;
public class FixAudioListener : MonoBehaviour {
// заполнить ссылку в инспекторе до старта игры
public PhotonView photonView;
private void Start() {
if (photonView.IsMine)
AddComponent<AudioListener>(); // добавить компоненту на камеру
}
}
public override void OnJoinedRoom()
public class PUN : MonoBehaviour
rb.velocity = Vector2.right * xInput * movementSpeed;
rb.velocity = new Vector2(xInput * movementSpeed, 0);
rb.velocity = new Vector2(xInput * movementSpeed, rb.velocity.y);
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
[DisallowMultipleComponent]
public class PlayerMovementDemo : MonoBehaviour {
private Rigidbody2D _Controller;
private float _MovementInput;
public float movementSpeed;
public float jumpingForce;
[Space(10)]
public Transform groundCheckPoint;
public float groundCheckDistance;
public LayerMask groundIdentity;
private void Start() {
_Controller = GetComponent<Rigidbody2D>();
}
private void Update() {
_MovementInput = Input.GetAxis("Horizontal");
if (Input.GetButtonDown("Jump") && IsGrounded())
_Controller.AddForce(Vector2.up * jumpingForce, ForceMode2D.Impulse);
}
private void FixedUpdate() {
_Controller.velocity = new Vector2(_MovementInput * movementSpeed, _Controller.velocity.y);
}
private bool IsGrounded() {
return Physics2D.OverlapCircle(groundCheckPoint.position, groundCheckDistance, groundIdentity);
}
}
using UnityEngine;
public class CharacterSelection : MonoBehaviour {
public GameObject[] characters;
private void Start() {
OnSelected(0);
}
public void OnSelected(int elementId) {
for (int i = 0; i < characters.Length; i++)
characters.SetActive(i == elementId);
}
}