Вот код:
Скрытый текст:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PLayer : MonoBehaviour
{
public GameObject player;
public GameObject Back;
public GameObject Face;
public GameObject Left;
public GameObject Right;
public float moveSpeed = 3f; // moveSpeed float count
void Update()
{
if (Input.GetKey(KeyCode.W))
{
player.transform.Translate(Vector3.up * moveSpeed * Time.deltaTime); // move up
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", true);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
Back.SetActive(true);
Face.SetActive(false);
Left.SetActive(false);
Right.SetActive(false);
}
if (Input.GetKeyUp(KeyCode.W))
{
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
}
if (Input.GetKey(KeyCode.S))
{
player.transform.Translate(Vector3.up * -moveSpeed * Time.deltaTime); // move down
Face.GetComponent<Animator>().SetBool("IsFaceRunning", true);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
Back.SetActive(false);
Face.SetActive(true);
Left.SetActive(false);
Right.SetActive(false);
}
if (Input.GetKeyUp(KeyCode.S))
{
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
}
if (Input.GetKey(KeyCode.D))
{
player.transform.Translate(Vector3.right * moveSpeed * Time.deltaTime); // move right
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", true);
Back.SetActive(false);
Face.SetActive(false);
Left.SetActive(false);
Right.SetActive(true);
}
if (Input.GetKeyUp(KeyCode.D))
{
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
}
if (Input.GetKey(KeyCode.A))
{
player.transform.Translate(Vector3.right * -moveSpeed * Time.deltaTime); // move left
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", true);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
Back.SetActive(false);
Face.SetActive(false);
Left.SetActive(true);
Right.SetActive(false);
}
if (Input.GetKeyUp(KeyCode.A))
{
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
}
}
}
using System.Collections.Generic;
using UnityEngine;
public class PLayer : MonoBehaviour
{
public GameObject player;
public GameObject Back;
public GameObject Face;
public GameObject Left;
public GameObject Right;
public float moveSpeed = 3f; // moveSpeed float count
void Update()
{
if (Input.GetKey(KeyCode.W))
{
player.transform.Translate(Vector3.up * moveSpeed * Time.deltaTime); // move up
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", true);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
Back.SetActive(true);
Face.SetActive(false);
Left.SetActive(false);
Right.SetActive(false);
}
if (Input.GetKeyUp(KeyCode.W))
{
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
}
if (Input.GetKey(KeyCode.S))
{
player.transform.Translate(Vector3.up * -moveSpeed * Time.deltaTime); // move down
Face.GetComponent<Animator>().SetBool("IsFaceRunning", true);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
Back.SetActive(false);
Face.SetActive(true);
Left.SetActive(false);
Right.SetActive(false);
}
if (Input.GetKeyUp(KeyCode.S))
{
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
}
if (Input.GetKey(KeyCode.D))
{
player.transform.Translate(Vector3.right * moveSpeed * Time.deltaTime); // move right
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", true);
Back.SetActive(false);
Face.SetActive(false);
Left.SetActive(false);
Right.SetActive(true);
}
if (Input.GetKeyUp(KeyCode.D))
{
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
}
if (Input.GetKey(KeyCode.A))
{
player.transform.Translate(Vector3.right * -moveSpeed * Time.deltaTime); // move left
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", true);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
Back.SetActive(false);
Face.SetActive(false);
Left.SetActive(true);
Right.SetActive(false);
}
if (Input.GetKeyUp(KeyCode.A))
{
Face.GetComponent<Animator>().SetBool("IsFaceRunning", false);
Back.GetComponent<Animator>().SetBool("IsBackRunning", false);
Left.GetComponent<Animator>().SetBool("IsLeftRunning", false);
Right.GetComponent<Animator>().SetBool("IsRightRunning", false);
}
}
}