当我点击一个按钮时,它在On Click中调用方法ActivatePlayer:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadSceneOnClick : MonoBehaviour
{
private Scene scene;
private void Start()
{
scene = SceneManager.GetActiveScene();
StartCoroutine(WaitForSceneUnLoad(SceneManager.GetSceneByName("The Space Station")));
}
public IEnumerator WaitForSceneUnLoad(Scene scene)
{
return null;
}
public void ActivatePlayer()
{
SceneManager.UnloadSceneAsync(0);
Cursor.visible = false;
GameControl.player.SetActive(true);
}
}
Run Code Online (Sandbox Code Playgroud)
但现在我想等待UnloadSceneAsync首先完成这一行:
SceneManager.UnloadSceneAsync(0);
Run Code Online (Sandbox Code Playgroud)
只有当它完成卸载时,其余两行:
Cursor.visible = false;
GameControl.player.SetActive(true);
Run Code Online (Sandbox Code Playgroud)
问题是,当我单击按钮时,我仍然会看到场景index0的第二个gui元素.索引中的场景是主菜单,当我单击按钮一秒钟时,我会看到主菜单文本的一部分.在卸载主菜单之前,它似乎正在激活播放器.由于主菜单和播放器都有摄像头的场景,我看到主菜单一秒钟.
设置新材质后,我想更改并设置3件事:
首先将着色器类型更改为“不亮/彩色”
Second反照率颜色,例如将其更改为:255,0,0,255
第三金属值从0到1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorsLockManager : MonoBehaviour
{
public bool locked;
public Color lockedColor = Color.red;
public Color unlockedColor = Color.green;
public Renderer rend;
private GameObject[] doorPlanes;
private void Start()
{
doorPlanes = GameObject.FindGameObjectsWithTag("DoorPlane");
for (int i = 0; i < doorPlanes.Length; i++)
{
rend = doorPlanes[i].GetComponent<Renderer>();
if (locked)
{
rend.material.SetFloat("Metallic", 1);
rend.material.color = lockedColor;
}
else
{
rend.material.color = unlockedColor;
}
}
}
// Update is called once per frame
void …Run Code Online (Sandbox Code Playgroud) 我没等,但我猜测同样的问题是分钟.当计时器倒计时并且秒数变为1时,它会变为59而不是先播种0.我不确定计时器的逻辑,如果在向上/向下计数时它应该显示0.
当它正在计算它的工作正常时,它在59之后显示为0.
private void timer1_Tick(object sender, EventArgs e)
{
if (countUpCheckbox.Checked)
{
Invoke(new Action(() =>
{
seconds += 1;
if (seconds == 60)
{
seconds = 0;
minutes += 1;
}
if (minutes == 60)
{
minutes = 0;
hours += 1;
}
richTextBox1.Text = string.Format("{0}:{1}:{2}", hours.ToString().PadLeft(2, '0'), minutes.ToString().PadLeft(2, '0'), seconds.ToString().PadLeft(2, '0'));
}));
}
if (countdownCheckbox.Checked)
{
Invoke(new Action(() =>
{
seconds -= 1;
if (seconds == 0)
{
seconds = 59;
minutes -= 1;
}
if (minutes == 0) …Run Code Online (Sandbox Code Playgroud) 作为参考,此代码来自对这个问题的回答:
突出显示颜色与 RichTextBox 文本中所有其他选择不同的单词或短语?
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
private class TextSearcher
{
private BindingSource m_bsMatches = null;
private RichTextBox m_Rtb = null;
public TextSearcher(RichTextBox rtb) : this(rtb, Color.Yellow, Color.Red) { }
public TextSearcher(RichTextBox rtb, Color selectionColor, Color currentColor)
{
this.m_Rtb = rtb;
SelectionColor = selectionColor;
CurrentColor = currentColor;
}
public string CurrentKeywords { get; private set; } = string.Empty;
public bool CaseSensitive { get; set; } = true;
public int CurrentIndex => m_bsMatches.Position;
public Match CurrentMatch …Run Code Online (Sandbox Code Playgroud) selected.GetComponent()
Run Code Online (Sandbox Code Playgroud)
selected是一个GameObject,我想找到它是否有任何组件,而不仅仅是特定的组件或类型.