
所以我想知道如何用编码改变我的死区宽度或高度,我有一个碰撞探测器,所以当我的播放器与那个矩形碰撞时,我想把死区宽度更改为2,但我不知道如何做到这一点,我试图在网上搜索答案,但没有,所以我想在这里询问是否有人知道答案。
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("dead"))
{
Debug.Log("Dead Zone Width Changed");
}
}我代码的其余部分:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class stopcamera : MonoBehaviour
{
public CinemachineVirtualCamera cam;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("dead"))
{
var composer = cam.GetCinemachineComponent<CinemachineComposer>();
composer.m_DeadZoneWidth = 2f;
Debug.Log("saman the third");
}
}
}发布于 2021-06-23 05:50:10
我想将死区宽度更改为2
若要更改Cinemachine虚拟相机的特定值,请执行以下操作。您首先需要获得ComponentBase of of (Aim、Body或Noise),这取决于您想要在哪个阶段更改值。你可以用GetCinemachineComponent(CinemachineCore.Stage.Body)做这件事。
然后更改所需的值,以确保将ComponentBase类型设置为与检查器中相同的值。在您的情况下,这将是CineMachineFramingTransposer。
示例:
[SerializeField]
private CinemachineVirtualCamera virtualCam;
private CinemachineComponentBase componentBase;
private void Start() {
// Get the componentBase of our virutalCam to adjust its values via code.
componentBase = virtualCam.GetCinemachineComponent(CinemachineCore.Stage.Body);
}
private void OnTriggerEnter2D(Collider2D other) {
if (!other.gameObject.CompareTag("dead")) {
return;
}
// Check if the CinemachineCore.Stage.Body ComponentBase,
// is set to the CinemachineFramingTransposer.
if (componentBase is CinemachineFramingTransposer) {
var framingTransposer = componentBase as CinemachineFramingTransposer;
// Now we can change all its values easily.
framingTransposer.m_DeadZoneWidth = 2f;
Debug.Log("Dead Zone Width Changed");
}
}https://stackoverflow.com/questions/68093734
复制相似问题