我有一个非常奇怪的问题。我已经下载了“ Bezier路径创建器” https://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082(下面的代码):
using UnityEngine;
using System.Collections.Generic;
namespace PathCreation
{
public class PathCreator : MonoBehaviour
{
/// This class stores data for the path editor, and provides accessors to get the current vertex and bezier path.
/// Attach to a GameObject to create a new path editor.
public event System.Action pathUpdated;
[SerializeField, HideInInspector]
PathCreatorData editorData;
[SerializeField, HideInInspector]
bool initialized;
// Vertex path created from the current bezier path
public VertexPath path
{
get
{
if (!initialized)
{
InitializeEditorData(false);
}
return editorData.vertexPath;
}
}
// The bezier path created in the editor
public BezierPath bezierPath
{
get
{
if (!initialized)
{
InitializeEditorData(false);
}
return editorData.bezierPath;
}
set
{
if (!initialized)
{
InitializeEditorData(false);
}
editorData.bezierPath = value;
}
}
#region Internal methods
/// Used by the path editor to initialise some data
public void InitializeEditorData(bool in2DMode)
{
if (editorData == null)
{
editorData = new PathCreatorData();
}
editorData.bezierOrVertexPathModified -= OnPathUpdated;
editorData.bezierOrVertexPathModified += OnPathUpdated;
editorData.Initialize(transform.position, in2DMode);
initialized = true;
}
public PathCreatorData EditorData
{
get
{
return editorData;
}
}
void OnPathUpdated()
{
if (pathUpdated != null)
{
pathUpdated();
}
}
#endregion
}
}
所以它真的很好用,我喜欢它。我将其用于电车系统。但是之后,我需要创建一个第三人称相机,并编写了这样的代码:
using UnityEngine;
using System.Collections;
public class CameraRotateAround : MonoBehaviour {
public Transform target;
public Vector3 offset;
public float sensitivity = 3;
public float limit = 80;
public float zoom = 0.25f;
public float zoomMax = 10;
public float zoomMin = 3;
private float X, Y;
void Start ()
{
limit = Mathf.Abs(limit);
if(limit > 90) limit = 90;
offset = new Vector3(offset.x, offset.y, -Mathf.Abs(zoomMax)/2);
transform.position = target.position + offset;
offset.z -= zoom + 3;
}
void Update ()
{
if(Input.GetAxis("Mouse ScrollWheel") > 0) offset.z += zoom;
else if(Input.GetAxis("Mouse ScrollWheel") < 0) offset.z -= zoom;
offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
X = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivity;
Y += Input.GetAxis("Mouse Y") * sensitivity;
Y = Mathf.Clamp (Y, -limit, 0);
transform.localEulerAngles = new Vector3(-Y, X, 0);
transform.position = transform.localRotation * offset + target.position;
}
}
在开始玩游戏的最初几秒钟,一切都很好,但是相机开始从电车上飞走了。我真的不知道该怎么办以及为什么会这样。
其中有一个关于使照相机远离电车飞行的视频:https://youtu.be/BXHnvq8bpPM。 谢谢您的帮助。