Помогите пожалуйста разбить скрипт на 3 части Run, Jump и всё оставшиеся.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Character : Unit
{
[SerializeField]
private int lives = 5;
public int Lives
{
get { return lives; }
set
{
if (value < 5) lives = value;
livesBar.Refresh();
}
}
private LivesBar livesBar;
[SerializeField]
private float speed = 3.0F;
[SerializeField]
private float jumpForce = 20.0F;
public bool isGrounded = false;
private Bullet bullet;
private CharState State
{
get { return (CharState)animator.GetInteger("State"); }
set { animator.SetInteger("State", (int)value); }
}
new public Rigidbody2D rigidbody;
public Animator animator;
public SpriteRenderer sprite;
private void Awake()
{
livesBar = FindObjectOfType<LivesBar>();
rigidbody = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
sprite = GetComponentInChildren<SpriteRenderer>();
bullet = Resources.Load<Bullet>("Bullet");
}
private void FixedUpdate()
{
CheckGround();
}
private void Update()
{
if (isGrounded) State = CharState.Idle;
if (Input.GetButtonDown("Fire1")) Shoot();
if (Input.GetButton("Horizontal")) Run();
if (isGrounded && Input.GetButtonDown("Jump")) Jump();
}
private void Run()
{
if (isGrounded) State = CharState.Run;
Vector3 direction = transform.right * Input.GetAxis("Horizontal");
transform.position = Vector3.MoveTowards(transform.position, transform.position + direction, speed * Time.deltaTime);
sprite.flipX = direction.x < 0.0f;
}
private void Jump()
{
State = CharState.Jump;
rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
private void Shoot()
{
Vector3 position = transform.position; position.y += 0.8F;
Bullet newBullet = Instantiate(bullet, position, bullet.transform.rotation) as Bullet;
newBullet.Parent = gameObject;
newBullet.Direction = newBullet.transform.right * (sprite.flipX ? -1.0F : 1.0F);
}
public override void ReceiveDamege()
{
Lives--;
rigidbody.velocity = Vector3.zero;
rigidbody.AddForce(transform.up * 8.0F, ForceMode2D.Impulse);
Debug.Log(lives);
if (Lives <= 0)// если жизней меньше либо равно нулю
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
private void CheckGround()
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 0.3F);
isGrounded = colliders.Length > 1;
if (!isGrounded) State = CharState.Jump;
}
private void OnTriggerEnter2D(Collider2D collider)
{
Bullet bullet = collider.gameObject.GetComponent<Bullet>();
if (bullet && bullet.Parent != gameObject)
{
ReceiveDamege();
}
}
}
public enum CharState
{
Idle,
Run,
Jump
}
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Виртуальный выделенный сервер (VDS) становится отличным выбором
Здравствуйте, пишу класс сервера, который мог бы обрабатывать несколько подключенийДо этого никогда не писал
Делаю модуль на сайте, который выводит пользователей на сайте за последние 24 часаВключил <anonymousIdentification enabled="true" /> на сайте
Не понимаю как правильно сделать чекбокс на показ пароля если отмеченЕсть вот такой код