using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class PlayerController : MonoBehaviour
{
CharacterController cc;
Animator anim;
public float speed = 2f;
public float runSpeed = 4f;
void Start ()
{
cc = GetComponent <CharacterController> ();
anim = GetComponent <Animator> ();
}
void Update ()
{
float x = Input.GetAxis ("Horizontal");
float z = Input.GetAxis ("Vertical");
if (x ! = 0)
{
transform.Rotate (0f, x * speed, 0f);
}
if (x ! = 0 || z ! = 0)
{
anim.SetBool ("walk",true);
Vector3 dir = transform.TransformDirection (new Vector3(x * speed * Time.deltaTime,0f,z * speed * Time.deltaTime));
cc.Move (dir);
}else
{
anim.SetBool ("walk",false);
}
if (Input.GetKey(KeyCode.W) && Input.GetKey (KeyCode.LeftShift)) // если на клаве нажата "w" или LeftShift
{
anim.SetBool ("run",true);
Vector3 dir = transform.TransformDirection (new Vector3(x * runSpeed * Time.deltaTime,0f,z * runSpeed * Time.deltaTime));
cc.Move (dir);
}else
{
anim.SetBool ("run",false);
}
}
}