unity 方向盘效果, 改变方向盘的位置 车自身位置跟随方向盘旋转 需要添加一个 boxcollider, 其中一个必须要有刚体, 通过刚体的碰撞来改变方向盘的方向,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShipComtrol : MonoBehaviour
{
public Transform ship;
public Vector3 vector3start;
void Start()
{
vector3start = transform.localPosition;
}
void Update()
{
}
private void LateUpdate()
{
}
private void FixedUpdate()
{
quaternion();
}
public void quaternion()
{
float y = transform.rotation.y * 50;
ship.rotation = Quaternion.Euler(0f, y, 0f);
}
private void OnCollisionEnter(Collision collision)
{
print("手碰到了");
}
private void OnCollisionExit(Collision collision)
{
print("手出来了");
transform.localPosition = vector3start;
transform.localRotation = new Quaternion(0, 0, 0, 0);
}
private void OnCollisionStay(Collision collision)
{
}
}
|