c# - 为什么我的 TMP 的面部颜色只在 50% 和 150% 时更新?
问题描述
Ello,我目前正在为本地多人 roguelike 开发一种机制,玩家之间的距离越近,他们造成的伤害就越大。到目前为止,我已经让乘数起作用并更改了伤害统计数据,但我无法像总乘数那样更新我的 % 文本。在目前的状态下,文本网格专业人士在每帧都应该更新的情况下,只有 50% 和 150% 的颜色更新。关于为什么会这样或任何潜在修复的任何想法?
谢谢
统计数据(对于 totalMultiplier)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Stats : MonoBehaviour
{
public GameObject midpoint;
public float baseDamage;
[SerializeField] private float damage;
[SerializeField] private float multiplier = 1;
public float totalMultiplier;
private float distMulti;
// Start is called before the first frame update
void Start()
{
multiplier = 1;
}
// Update is called once per frame
void Update()
{
//actual multiplier
damage = (baseDamage * multiplier) / (midpoint.GetComponent<Midpoint>().distance * 0.5f);
if (damage >= (baseDamage * multiplier * 2))
{
damage = (baseDamage * multiplier * 2);
}
//Keep track of multiplier
totalMultiplier = damage / baseDamage;
}
}
Text Tracker / Color Changer(使用设置 faceColor 编辑 TMP 着色器)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class TextTracker : MonoBehaviour
{
public GameObject player;
private TextMeshPro text;
private Color redAmount = Color.red;
// Start is called before the first frame update
void Start()
{
text = GetComponent<TextMeshPro>();
}
// Update is called once per frame
void Update()
{
text.SetText(System.Math.Round((player.GetComponent<Stats>().totalMultiplier)* 100, 0).ToString() + "%");
transform.position = new Vector2(player.transform.position.x, player.transform.position.y + 1);
Shader color = text.material.shader;
text.faceColor = new Color(1f, 1f - (float)System.Math.Round(player.GetComponent<Stats>().totalMultiplier) / 2, 1f - (float)System.Math.Round(player.GetComponent<Stats>().totalMultiplier) / 2, 1f);
}
}
解决方案
是的,我的问题是 Math.Round 函数。它被设置为 0,所以它只会四舍五入到整数。增加它可以解决所有问题。
推荐阅读
- reactjs - 带有安装的反应酶测试用例给出“不变违规:超出最大更新深度”问题
- swiftui - 父母可以知道其子 ForEach 的当前迭代吗
- windows - Inno Setup“源文件 C:\Windows\System32\vcruntime140_1.dll 不存在”错误
- google-apps-script - 使用 Google 脚本创建和/或更新邮件合并 Google 文档
- rxjs - 不推荐使用 4 种订阅方法中的 3 种时如何订阅 NavigationEnd 事件
- python - 来自 pandas 的 Networkx 图,其中的节点具有不连接其他节点的边和没有边的节点
- google-sheets - 添加新选项卡时主表更新
- powershell - 使用现有的 json 文件使用 Pester 和 TestDrive 进行测试
- java - 使用嵌套的 for 循环为二维数组赋值
- azure - 从 Azure 托管应用调用 Azure 自定义提供程序操作