您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

32 行
767 B

using UnityEngine;
public class ParallaxLayer : MonoBehaviour
{
[SerializeField] float multiplier = 0.0f;
[SerializeField] bool horizontalOnly = true;
private Transform cameraTransform;
private Vector3 startCameraPos;
private Vector3 startPos;
void Start()
{
cameraTransform = Camera.main.transform;
startCameraPos = cameraTransform.position;
startPos = transform.position;
}
private void LateUpdate()
{
var position = startPos;
if (horizontalOnly)
position.x += multiplier * (cameraTransform.position.x - startCameraPos.x);
else
position += multiplier * (cameraTransform.position - startCameraPos);
transform.position = position;
}
}