0

由于在其他任何地方都没有找到解决方案,所以问这个问题。

我创建了一个无限视差滚动背景,但现在无论我带着角色走到哪里,瓦片地图都跟着我?

由于我正在使用 Cinemachine 包,这可能是一个错误吗?

这是我的视差脚本。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Parallax : MonoBehaviour
{
    private float length, startpos;
    public GameObject cam;
    public float parallaxEffect;

    // Start is called before the first frame update
    void Start()
    {
        startpos = transform.position.x;
        length = GetComponent<SpriteRenderer>().bounds.size.x;
    }

    // Update is called once per frame
    void Update()
    {
        float temp = (cam.transform.position.x * (1 - parallaxEffect));
        float dist = (cam.transform.position.x * parallaxEffect);

        transform.position = new Vector3(startpos + dist, transform.position.y, transform.position.z);

        if (temp > startpos + length) startpos += length;
        else if (temp < startpos - length) startpos -= length;

    }
}

瓦片地图网格都有地面标签和图层,没有以任何方式连接到背景。

如果有人可以帮助我发现问题,非常感谢!

编辑

如果有人有问题,我添加了图像以更清楚地描述问题。

查看变换 X 瓦片地图如何跟随玩家。

4

0 回答 0