坦克世界脚本按键脚本
❶ 为什么近几坦克世界天盒子不能用
能用啊,我刚才还玩的。你把你的坦克世界盒子全卸载,然后把整个文件夹删除,再重新下载盒子安装试试,我估计是你的插件出了问题,用了限时插件或者新插件,单纯在盒子里卸载插件不行,弄不干净,必须把文件夹全部删除后重装。
❷ unity 3d怎么才能让坦克炮塔像坦克世界里一样鼠标移到一定位置然后炮塔慢慢跟上来的那种 有c#源码最好
把下面的脚本挂载到要转的物体上
using UnityEngine;
using System.Collections;
public class RobotTurret : MonoBehaviour {
[SerializeField]
private float RotateSpeed = 720f;
[SerializeField]
[Range(0f, 180f)]
private float Limit = 180f;
private float InitLocalRotY = 0f;
void Start () {
InitLocalRotY = transform.localRotation.eulerAngles.y % 360f;
}
void Update () {
Vector3 MouseWorldPosition = Vector3.zero;
Plane plane = new Plane(Vector3.up, transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float distance;
if (plane.Raycast(ray, out distance)) {
MouseWorldPosition = ray.origin + ray.direction * distance;
}
Vector3 pos = MouseWorldPosition;
pos.y = transform.position.y;
Quaternion aimRot = Quaternion.RotateTowards(
transform.rotation,
Quaternion.LookRotation(
pos - transform.position,
Vector3.up
),
Time.deltaTime * RotateSpeed
);
transform.rotation = aimRot;
// Clamp
float localY = Mathf.Repeat(transform.localRotation.eulerAngles.y + 180f, 360f) - 180f;
if (Mathf.Abs(Mathf.Abs(localY % 360f) - Mathf.Abs(InitLocalRotY)) > Limit) {
transform.localRotation = Quaternion.Euler(0f, InitLocalRotY + (localY > 0f ? Limit : -Limit), 0f);
}
}
}