【发布时间】:2015-09-11 01:12:35
【问题描述】:
无法让这条线正常工作,它需要一个临时变量。没有它,相机会平放在地面上
transform.position.y = currentHeight;
错误 CS1612:无法修改“UnityEngine.Transform.position”的值类型返回值。考虑将值存储在临时变量中
部分代码不是我的,只是试图从java脚本转换为c-sharp并在我当前的相机脚本中实现
// Calculate the current rotation angles
var wantedRotationAngle = target.eulerAngles.y;
var wantedHeight = target.position.y + height;
var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;
// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position.y = currentHeight;
// Always look at the target
transform.LookAt (target);
【问题讨论】: