我想在已知的路径中找到该文件,如果它在android中预先存在,则用它触发事件(启用/禁用画布).这是我用过的一个例子 -
public void FileChk(){
string filePath = "file://" + Application.temporaryCachePath + "/" + "folder23" + "/" + fileName;
if (!fileName.Exists)
{
//event
}
else
{
//event
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么以及如何在文件存在时触发此事件.
我使用Unity 2018并使用C#,我想检查我的布尔值是否为真。这是我的代码:
public class ShopButtonClick : MonoBehaviour
{
bool shopOpened = false;
public GameObject upgradeOne;
public void ClickTheButton()
{
if (shopOpened)
{
shopOpened = false;
upgradeOne.SetActive(false);
}
else
shopOpened = true;
upgradeOne.SetActive(true);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是它不起作用,我将脚本添加到了按钮上,但它不起作用,在我的其他项目中它可以正常工作……但是由于某种原因,现在不行了。
嗨我在c#中的脚本的以下协程部分有问题.我得到的错误信息附在屏幕抓取中,似乎是:GetComponent<Renderer>().
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
public class test: MonoBehaviour
{
public float model2;
public float model1;
public void section1()
{
SceneManager.LoadScene("section1", LoadSceneMode.Single);
}
public void fade()
{
StartCoroutine(colorlerpin());
}
public IEnumerator colorlerpin()
{
float ElapsedTime2 = 0.0f;
float TotalTime2 = 1f;
while (ElapsedTime2 < TotalTime2)
{
// fades out main heart
ElapsedTime2 += Time.deltaTime;
model1.GetComponent<Renderer>().material.color = Color.Lerp(new Color(1f, 1f, 1f, 1f), new Color(1f, 1f, 1f, 0f), (ElapsedTime2 / TotalTime2));
yield return null;
// fades in cutaway …Run Code Online (Sandbox Code Playgroud) 在我的游戏中,我有一个用于切换武器的脚本。该脚本依赖于gameObjects您所选择的激活和停用。截至目前,gameObjectsget 在 unity 中设置为非活动状态,但activeSelf无论实际状态如何,该函数都会返回 true。附上我的脚本的一部分。If 语句运行良好,我可以监视 中的状态Debug.Log。
这不应该发生,我不知道原因是什么。