使用Cinemachine Confiner設置攝像機邊界
前提提要:在做這個功能前需要:
? main camera
? 另外一個相機
思路:創(chuàng)建一個對象綁定Polygon Collider2D 邊界。然后在另外一個相機Cinemachine Confiner上綁定他
? 綁定邊界
記得點這個,否則會收重力影響
? 在另外一個相機Cinemachine Confiner上綁定他
我們用代碼嘗試找到我們的bouns對象
? bounds對象添加好標簽
? 給相機裝上腳本,找到我們的bounds對象
SwitchBounds.cs
:文章來源:http://www.zghlxwxcb.cn/news/detail-792564.html
using System.Collections;
using System.Collections.Generic;
using Cinemachine;
using UnityEngine;
public class SwitchBounds : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
SwitchConfinerShape();
}
private void SwitchConfinerShape()
{
PolygonCollider2D confinerShape = GameObject.FindGameObjectWithTag("BoundsConfiner").GetComponent<PolygonCollider2D>();
CinemachineConfiner confiner = GetComponent<CinemachineConfiner>();
confiner.m_BoundingShape2D = confinerShape;
//清除緩存
confiner.InvalidatePathCache();
}
}
就完成了我們的移動,這樣我們的角色就走不出地圖。文章來源地址http://www.zghlxwxcb.cn/news/detail-792564.html
到了這里,關于Unity--使用Cinemachine Confiner設置攝像機邊界的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!