Скрипт простой но очень хороший, он предназначен для 2D камер, скрипт отслеживает объект и камера плавно следит за объектом
Синтаксис:
Используется javascript
#pragma strict
var target : Transform;
var smoothTime = 0.5;
private var thisTransform : Transform;
private var velocity : Vector2;
function Start()
{
thisTransform = transform;
}
function Update()
{
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x,
target.position.x, velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y+10, velocity.y, smoothTime);
}
var target : Transform;
var smoothTime = 0.5;
private var thisTransform : Transform;
private var velocity : Vector2;
function Start()
{
thisTransform = transform;
}
function Update()
{
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x,
target.position.x, velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y+10, velocity.y, smoothTime);
}
Сам я уже пробовал перевести, вот рез-тат:
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class Cam : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.5f; //this might be a dobbelt
private Transform thisTransform;
private Vector2 velocity;
void Start()
{
thisTransform = transform;
}
void Update()
{
thisTransform.position = new Vector3(Mathf.SmoothDamp( thisTransform.position.x,
target.position.x, ref velocity.x, smoothTime), 0, 0);
thisTransform.position = new Vector3(0, Mathf.SmoothDamp( thisTransform.position.y,
target.position.y, ref velocity.y, smoothTime), 0);
}
}
using System.Collections;
public class Cam : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.5f; //this might be a dobbelt
private Transform thisTransform;
private Vector2 velocity;
void Start()
{
thisTransform = transform;
}
void Update()
{
thisTransform.position = new Vector3(Mathf.SmoothDamp( thisTransform.position.x,
target.position.x, ref velocity.x, smoothTime), 0, 0);
thisTransform.position = new Vector3(0, Mathf.SmoothDamp( thisTransform.position.y,
target.position.y, ref velocity.y, smoothTime), 0);
}
}
ошибок компилятор не выдает, но камера почему-то постоянно дергается, пол дня уже угробил на это дело, подскажите что не так или может на шарпе вобще по другому надо делать?