我正在玩Unity的渲染纹理,你可以将相机的视图渲染到纹理上.但是,我注意到它没有呈现整个相机的视图.它只渲染摄像机视图的方形切片.
我正在尝试的是将相机的整个视图(16:9宽高比)渲染到纹理上(也是16:9的宽高比).但是现在它似乎只能在方形表面上投影其方形切片.这有什么解决方案吗?
我目前正在开发一个健康栏,慢慢消耗你的健康状况.我按照本教程获取了我想要的健康栏:https://www.youtube.com/watch?v = NgftVg3idB4
简而言之,它使用遮罩层和单独的绿色条来指示健康状况.通过向左移动绿色条,它会消失在遮罩层后面,从而显示出越来越少的健康状况.根据健康状况计算其位置的方法如下:代码(CSharp):
float maxXValue = healthTransform.position.x;
float minXValue = healthTransform.position.x - healthTransform.rect.width;
private void HandleHealth()
{
Stats attachedStats = attachedObject.GetComponent<Stats>();
float currentXValuePlayer = MapValues(attachedStats.currentHealth, 0, attachedStats.maxHealth, minXValue, maxXValue);
healthTransform.position = new Vector3(currentXValuePlayer, cachedY);
}
private float MapValues(float x, float inMin, float inMax, float outMin, float outMax)
{
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
/*
EXPLANATION:
attachedStats.currentHealth is the current health the player has
attachedStats.maxHealth is the …Run Code Online (Sandbox Code Playgroud)