码迷,mamicode.com
首页 > 其他好文 > 详细

u3d Animator和脚本控制FPS骑士

时间:2017-11-11 22:16:50      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:vector   etc   oat   star   nim   inpu   speed   ace   trigger   

using UnityEngine;
using System.Collections;

public class PlayerMove : MonoBehaviour {

Transform _head;
Animator _animator;

void Start () {

_head = transform.FindChild("Head");
_animator = GetComponent<Animator>();
}


void Update () {
Move();
Rotate();
Run();
Jump();
}

public float moveSpeed =10f;
void Move()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");

bool isWalking = horizontal != 0 || vertical != 0;
_animator.SetBool("Walk", isWalking);


bool isBacking = Input.GetKey(KeyCode.S);
_animator.SetBool("Back", isBacking);



bool isLefting = horizontal < 0;
_animator.SetBool("Left",isLefting);

bool isRighting = horizontal > 0;
_animator.SetBool("Right",isRighting);


bool walkFight = (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2))&&(isWalking || isLefting || isRighting || isBacking);
_animator.SetBool("WalkFight", walkFight);
if (walkFight)
{
if (Input.GetMouseButtonDown(0) )
{
_animator.SetTrigger("WalkSwingLeft");
}
if (Input.GetMouseButtonDown(1))
{
_animator.SetTrigger("WalkSwingRight");
}
if (Input.GetMouseButtonDown(2))
{
_animator.SetTrigger("WalkTrust");
}
}

if (horizontal==0&&vertical==0)
{
_animator.SetBool("Walk",false);
if (Input.GetMouseButtonDown(0))
{
_animator.SetTrigger("SwingLeft");
}
if (Input.GetMouseButtonDown(1))
{
_animator.SetTrigger("SwingRight");
}
if (Input.GetMouseButtonDown(2))
{
_animator.SetTrigger("Trust");
}

}
Vector3 desPos = (transform.right * horizontal + transform.forward * vertical) * Time.deltaTime * moveSpeed;
transform.position += desPos;
}
public float rotateSpeed = 1f;
void Rotate()
{
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");

transform.Rotate(Vector3.up*mouseX*rotateSpeed);
_head.Rotate(-Vector3.right * mouseY * rotateSpeed);

}

public void Run()
{
bool isRuning = Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift);
_animator.SetBool("Run", isRuning);
if (isRuning)
{
moveSpeed = 6f;
}
else
{
moveSpeed = 3f;
}
}

public void Jump()
{
if (Input.GetKeyDown(KeyCode.Space))
{
_animator.SetTrigger("Jump");
}
}

void WalkSwing()
{

}
}技术分享

u3d Animator和脚本控制FPS骑士

标签:vector   etc   oat   star   nim   inpu   speed   ace   trigger   

原文地址:http://www.cnblogs.com/wanggonglei/p/7820035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!