Unity3D の Main Camera オブジェクトで使用するスクリプトを作成しているため、カメラは 2D プラットフォーマーの世界でキャラクターを追跡します。
これを UnityScript スクリプトから C# に変換しようとすると、26 行目でエラーが発生します。
元の UnityScript バージョン
var cameraTarget : GameObject;
var player : GameObject;
var smoothTime : float = 0,1;
var cameraFollowX : boolean = true;
var cameraFollowY : boolean = true;
var cameraFollowHeight : boolean = false;
var cameraHeight : float = 2.5;
var velocity : Vector2;
private var thisTransform : Transform;
function Start ()
{
thisTransform = transform;
}
function Update ()
{
if (cameraFollowX)
{
thisTransform.position.x = Mathf.SmoothDamp (thisTransform.position.x, cameraTarget.transform.position.x, velocity.x, smoothTime);
}
if (cameraFollowY)
{
thisTransform.position.y = Mathf.SmoothDamp (thisTransform.position.y, cameraTarget.transform.position.y, velocity.y, smoothTime);
}
if (!cameraFollowX & cameraFollowHeight)
{
camera.transform.position.y = cameraHeight;
}
}
私のC#バージョン
using UnityEngine;
using System.Collections;
public class CameraSmoothFollow : MonoBehaviour {
public GameObject cameraTarget; // object to look at or follow
public GameObject player; // player object for moving
public float smoothTime = 0.1f; // time for dampen
public bool cameraFollowX = true; // camera follows on horizontal
public bool cameraFollowY = true; // camera follows on vertical
public bool cameraFollowHeight = true; // camera follow CameraTarget object height
public float cameraHeight = 2.5f; // height of camera adjustable
public Vector2 velocity; // speed of camera movement
private Transform thisTransform; // camera Transform
// Use this for initialization
void Start () {
thisTransform = transform;
}
// Update is called once per frame
void Update () {
if (cameraFollowX){
thisTransform.position.x = Mathf.SmoothDamp (thisTransform.position.x, cameraTarget.transform.position.x, ref velocity.x, smoothTime); // Here i get the error
}
if (cameraFollowY) {
// to do
}
if (!cameraFollowX & cameraFollowHeight) {
// to do
}
}
}
どんな助けでも大歓迎です。