Unity3d 如何让背景与玩家的高度在统一中滚动?
我正在做一件无休止的跳伞。我正试图让背景根据球员的身高向下滚动 我见过以特定速度移动代码的代码:Unity3d 如何让背景与玩家的高度在统一中滚动?,unity3d,Unity3d,我正在做一件无休止的跳伞。我正试图让背景根据球员的身高向下滚动 我见过以特定速度移动代码的代码: public float speed = .5f; void Updated(){ Vector2 offset = new Vector2(0, Time.deltatime * speed); GetComponent<Renderer>().material.mainTextureOffset = offset; } 所以现在我需要设置背景的高度。我不知
public float speed = .5f;
void Updated(){
Vector2 offset = new Vector2(0, Time.deltatime * speed);
GetComponent<Renderer>().material.mainTextureOffset = offset;
}
所以现在我需要设置背景的高度。我不知道怎么做这部分
Transform background;
public float backgroundHeightY;
public GameObject BackGround;
从这里我被困住了。我不想让它随着摄像机移动,但要根据球员的身高以一定的速度移动。任何帮助都会很棒。听起来你的背景相对于相机有一个固定的位置,但是你想让背景在播放器上下移动时“对着”播放器滚动,从而产生视差效果
public Transform player;
public float multiplier = 0.1f; //Tweak this
void Update(){
Vector2 offset = new Vector2(0, player.position.y * multiplier);
GetComponent<Renderer>().material.mainTextureOffset = offset;
}
公共转换播放器;
公共浮动乘数=0.1f//调整这个
无效更新(){
向量2偏移=新向量2(0,player.position.y*乘数);
GetComponent().material.mainTextureOffset=偏移量;
}
我让它向上运行良好,但没有向下运行。下面是它的工作原理。我已经调整了背景修改器以适应我需要的时间
//Changes the BG position
changeAmount = (playerHeightY - currentCameraHeight)/backgroundModifier;
Vector3 temp = new Vector3(0, changeAmount, 0);
BackGround.transform.position += temp;
任何人都知道如何让坠落开始工作。我觉得我让这件事变得比需要的更难了。以下是我最终是如何做到这一点的。实际上我把相机从正交切换到了透视。对布局进行了很多调整,但最终效果非常好。因此,我删除了上面的代码。为什么不计算帧间播放器高度的差异,然后将该值添加或减去背景的当前位置?这是正确的。但是我如何将其与BG绑定?我现在得到了这个错误:材质纹理属性\u MainTex设置了偏移/缩放。它与Sprite Rendery不兼容如果你想使用它,你必须使用常规的网格渲染器(可能是四边形)。谢谢你,我最后把相机改成了透视。
//Changes the BG position
changeAmount = (playerHeightY - currentCameraHeight)/backgroundModifier;
Vector3 temp = new Vector3(0, changeAmount, 0);
BackGround.transform.position += temp;