@Valentin123

Сохранение в unity проекте с помощью yandex game?

код
using System.Collections;
using System.Collections.Generic;
using Unity.Loading;
using UnityEngine;
using UnityEngine.SceneManagement;

public class RobloxianController : MonoBehaviour
{
    Rigidbody rb;

    public class PlayerInfo
    {

    }
    public CharacterController controller;
    public Transform cam;
    public Transform groundCheck;
    public Animator animator;

    public float gravity = -9.81f;

    public float speed = 6f;
    public float jumpSpeed = 5;
    public float turnSmoothTime = 0.1f;

    public float groundDistance = 0.4f;

    Vector3 velocity;
    bool isJumping;
    public LayerMask groundMask;

    bool isGrounded;
    bool isMoving;


    public float jumpHeight = 3f;

    float turnSmoothVelocity;

    [SerializeField] GameObject player;
    [SerializeField] List<GameObject> checkPoints;
    [SerializeField] Vector3 vectorPoint;
    [SerializeField] float dead;

    // Update is called once per frame
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        StartCoroutine(ResetJump());

    }
    IEnumerator ResetJump()
    {
        while (true)
        {
            yield return new WaitForFixedUpdate();
            isJumping = false;
        }
    }
    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;

        if (direction.magnitude >= 0.1f)
        {

            float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
            transform.rotation = Quaternion.Euler(0f, angle, 0f);

            Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
            controller.Move(moveDir.normalized * speed * Time.deltaTime);
            isMoving = true;
        }
        if (Input.GetButtonDown("Jump") && isGrounded && !isJumping)
        {
            StartCoroutine(Jump());
        }

        if (direction.magnitude <= 0.0f)
        {
            isMoving = false;
        }

        if (isGrounded != true)
        {
            animator.SetBool("Robloxian In Air", true);
        }
        else
        {
            animator.SetBool("Robloxian In Air", false);
            isJumping = false; // Сбрасываем флаг isJumping в false при приземлении
        }
        if (isMoving)
        {
            animator.SetBool("Robloxian In Move", true);
        }
        else if (!isMoving)
        {
            animator.SetBool("Robloxian In Move", false);
        }

        velocity.y += gravity * Time.deltaTime;

        controller.Move(velocity * Time.deltaTime);

        if (player.transform.position.y < -dead)
        {
            player.transform.position = vectorPoint;
        }
        IEnumerator Jump()
        {
            isJumping = true;
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
            yield return new WaitForSeconds(0.1f);
            isJumping = false;
        }
    }

    public void OnTriggerEnter(Collider other)
    {

        vectorPoint = player.transform.position;

        Destroy(other.gameObject);

        if (other.gameObject.CompareTag("JumpPad"))
        {
            velocity.y = Mathf.Sqrt(8f * -2f * gravity);
        }
        else if (other.gameObject.CompareTag("JumpPadToSky"))
        {
            velocity.y = Mathf.Sqrt(40f * -2f * gravity);
        }
        else if (other.gameObject.CompareTag("JumpPadMush"))
        {
            velocity.y = Mathf.Sqrt(52f * -2f * gravity);
        }
    }
}
  • Вопрос задан
  • 103 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы