using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerTanke : TankeBase {
protected override void Start()
{
base.Start();
//隐藏鼠标
Cursor.lockState = CursorLockMode.Locked;
}
private float hitDuring;
private float xRotationAllSize;//炮台沿着X轴旋转总大小
protected override void Update()
{
base.Update();
float horizonta = Input.GetAxis("Horizontal");
float verticalValue = Input.GetAxis("Vertical");
//转向
if (horizonta != 0)
{
wheel_colliders[0].steerAngle = horizonta * 50f;
wheel_colliders[1].steerAngle = horizonta * 50f;
}
// Debug.Log("horizontalValue:" +(horizonta * 50f * Time.deltaTime));
//前进
if (verticalValue != 0)
{
wheel_colliders[2].motorTorque = verticalValue * 1000f;
wheel_colliders[3].motorTorque = verticalValue * 1000f;
AudioManager.Instance.PlaySound(move_sound);
}
//炮台左右旋转 旋转Y轴
float mouseX = Input.GetAxis("Mouse X");
if (mouseX != 0 && turret != null)
{
turret.localEulerAngles += Vector3.up * mouseX * Time.deltaTime * 20;//每秒旋转20度
}
//炮台上下旋转 旋转X轴
float mouseY = Input.GetAxis("Mouse Y");
if (mouseY != 0)
{
// turret.Rotate(Vector3.right * mouseY * Time.deltaTime * 5);
//旋转角度,限制在-45度 和20度之间
xRotationAllSize += -mouseY * 5 * Time.deltaTime;
if (xRotationAllSize <= 20 && xRotationAllSize >= -45)
{
turret.Rotate(-mouseY * 5 * Time.deltaTime, 0, 0, Space.Self);
}
xRotationAllSize = Mathf.Clamp(xRotationAllSize, -45, 20);
// xRotationAllSize += ;
//turret.localEulerAngles += Vector3.left * mouseY * Time.deltaTime * 30;
Debug.Log("xRotationAllSize:" + xRotationAllSize);
}
//开火
hitDuring += Time.deltaTime;
if (hitDuring > 0.3f && Input.GetMouseButton(0))
{
hitDuring = 0;
Fire();
}
//刹车
if (Input.GetMouseButton(1))
{
wheel_colliders[0].brakeTorque = 3000f;
wheel_colliders[1].brakeTorque = 3000f;
wheel_colliders[2].brakeTorque = 3000f;
wheel_colliders[3].brakeTorque = 3000f;
}
else
{
wheel_colliders[0].brakeTorque = 0;
wheel_colliders[1].brakeTorque = 0;
wheel_colliders[2].brakeTorque = 0;
wheel_colliders[3].brakeTorque = 0;
}
}
}