在 OnTriggerEnter Unity 中更改文本的 CanvasGroup 的 alpha
Changing alpha of Text's CanvasGroup in OnTriggerEnter Unity
我目前正在开发一款向 Marble Blast 致敬的游戏 Gold/Ultra。
在这一点上,我有与大理石一起定位的文本。该文本是 canvas 的子项,我在文本中添加了一个 canvas 组。我最初将 canvas 组的 alpha 设置为 0,这样您就看不到文字了。
我想要做的是,当你拿起电源时,文本会重新出现,方法是将 canvas 组的 alpha 更改回 1,然后在使用电源后设置它回到 0.
我目前的代码似乎没有任何运气。
// Super Jump pickup
if (col.gameObject.tag == "Spring")
{
superJumpText.GetComponent<CanvasGroup>().alpha = 1;
canSuperJump = true;
canSuperSpeed = false;
col.gameObject.SetActive(false);
hitSuperJump = true;
Invoke("Display", 20);
}
void Update()
{
//super jump
if (canSuperJump)
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Vector3 jump = new Vector3(0, superJumpForce, 0);
GetComponent<Rigidbody>().AddForce(jump);
canSuperJump = false;
superJumpText.GetComponent<CanvasGroup>().alpha = 0;
}
}
}
这对您不起作用的唯一原因是在您的父层次结构中的某个地方,您有一个游戏对象与另一个 canvas 组。这将始终覆盖子 canvas 组设置,除非您 select 子 canvas
中的 'Ignore Parent Groups'
复选框
我目前正在开发一款向 Marble Blast 致敬的游戏 Gold/Ultra。
在这一点上,我有与大理石一起定位的文本。该文本是 canvas 的子项,我在文本中添加了一个 canvas 组。我最初将 canvas 组的 alpha 设置为 0,这样您就看不到文字了。
我想要做的是,当你拿起电源时,文本会重新出现,方法是将 canvas 组的 alpha 更改回 1,然后在使用电源后设置它回到 0.
我目前的代码似乎没有任何运气。
// Super Jump pickup
if (col.gameObject.tag == "Spring")
{
superJumpText.GetComponent<CanvasGroup>().alpha = 1;
canSuperJump = true;
canSuperSpeed = false;
col.gameObject.SetActive(false);
hitSuperJump = true;
Invoke("Display", 20);
}
void Update()
{
//super jump
if (canSuperJump)
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Vector3 jump = new Vector3(0, superJumpForce, 0);
GetComponent<Rigidbody>().AddForce(jump);
canSuperJump = false;
superJumpText.GetComponent<CanvasGroup>().alpha = 0;
}
}
}
这对您不起作用的唯一原因是在您的父层次结构中的某个地方,您有一个游戏对象与另一个 canvas 组。这将始终覆盖子 canvas 组设置,除非您 select 子 canvas
中的'Ignore Parent Groups'
复选框