我试图弄清楚如何在当前日期时间中添加一天以便稍后进行比较。如果用户单击按钮,我希望能够在一天内关闭应用程序中的一项功能。因此,当设置的日期时间+24 小时低于当前日期时间时,它将重新激活。
我知道如何获取当前日期时间,如下所示:
static DateTime now = DateTime.UtcNow;
Run Code Online (Sandbox Code Playgroud)
但我想这样做:
static DateTime deactivateDate = DateTime.UtcNow+24;
Run Code Online (Sandbox Code Playgroud)
如有任何帮助,我们将不胜感激:-)
我面临着有关统一 UI 元素的问题。
我正在为所有 Facebook 好友的分数制作一个排行榜,就像钢琴块一样。
我尝试在运行时实例化 UI 元素,但无法实现。我想在 for 循环中为 UI 文本和 UI 图像分配随机值。
我制作了一系列面板,并根据我的要求激活和停用它们。
我得到了父级,但我不知道如何找到它的子级(这些子级是 UI 元素)并分配一个值。
我需要使用 c# 脚本计算和显示从我的车到终点的情况(这里的问题是,在运行时某些任务目的地会发生变化)?需要一些帮助。
看我的gif,在播放模式下,我更改私有字段并在Unity编辑器中刷新,我确定脚本代码已刷新,但为什么游戏toolwin无法更新?我知道unity播放模式可以自动刷新,为什么这个私有字段不更新

控制台总是提出:
The referenced script on this Behaviour is missing!
Run Code Online (Sandbox Code Playgroud)
我不知道什么意思
我目前正在 Unity 2018 中进行开发,并制作了一个脚本来降低角色与敌人碰撞时的生命值:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthManager : MonoBehaviour
{
public static int currentHealth;
public Slider healthBar;
void Awake()
{
healthBar = GetComponent<Slider> ();
currentHealth = 100;
}
void ReduceHealth()
{
currentHealth = currentHealth - 1;
healthBar.value = currentHealth;
}
void Update()
{
healthBar.value = currentHealth;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在敌人的脚本文件中使用上述方法时,出现错误,指出“Assets/Custom Scripts/BeetleScript.cs(46,28): error CS0122: `HealthManager.ReduceHealth()' 由于其保护而无法访问等级”
以下是敌人脚本启动正在使用的变量并调用方法:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BeetleScript : MonoBehaviour
{
Animator animator;
public GameObject cucumberToDestroy; …Run Code Online (Sandbox Code Playgroud) 越过山丘时, NavmeshAgent 玩家与山坡不平行。在平面上它进展顺利。
下面是navMesh 和播放器的 图像属性https://ibb.co/fijmoV
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class SampleAgentScript : MonoBehaviour {
public Transform target ;
NavMeshAgent agent;
// private static bool start1=false , start2=false, start3;
// Use this for initialization
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
//if white button click moves to targer-1
agent.SetDestination(target.position);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一种可以采用“按住“E”进行交互”类型的输入的情况。我的第一个想法是,按住按钮后启动计时器。计时器达到 700 毫秒后,采取行动。但问题是我不知道如何用 C# 编写它,因为我是这门语言的新手。任何其他方法也值得赞赏。
我在这里添加伪代码
//pseudocode
//inside the update function
if (e is pressed)
{
start timer;
if (timer.time == 700)
{
Debug.Log("E is pressed for quite some time");
}
}
Run Code Online (Sandbox Code Playgroud) 我知道这是一个非常基本的问题(我对 C# 比较陌生),但不知何故我在互联网上找不到任何有关它的信息。
我只是想了解“%”运算符的作用,我以前见过应用程序并且有一些想法,但不能 100% 确定它到底做什么。
例如,下面是每 10 帧执行一次的方法(在 Unity 中):
void Update() {
frames++;
if (frames % 10 == 0) {
// method
}
}
Run Code Online (Sandbox Code Playgroud)
下面是显示的游戏时间计算:
// time = incremented by 1 every second
int seconds = (time % 60);
int minutes = (time / 60) % 60;
int hours = (time / 3600) % 24;
// int days = (time / 86400) % 365;
Run Code Online (Sandbox Code Playgroud)
在这些示例中 % 运算符到底做了什么以及我怎样才能最好地理解它。
我想以编程方式修改附加到“损坏弹出”游戏对象的矩形变换组件的“缩放”参数(特别是 x 缩放),如附图所示;但是,我似乎无法修改这个值。我尝试了几种方法(代码如下所示),但似乎没有任何效果。
非常感谢任何帮助或指导!
Vector3 rectScale;
RectTransform rectTransform;
float xScale;
// Start is called before the first frame update
void Start()
{
rectTransform = GetComponent<RectTransform>();
rectScale = rectTransform.localScale;
rectScale = new Vector3(3f, transform.localScale.y, transform.localScale.z); //this doesn't work
xScale = rectTransform.localScale.x;
xScale = *any number*; // this doesn't work
}
void Update()
{
rectScale = new Vector3(3f, transform.localScale.y, transform.localScale.z); //this doesn't work
xScale = *any number* //this doesn't work
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使 Unity 中的按钮只能每隔几秒钟按下并激活。我有一个包含名言的数组,当我按下按钮时,它会显示这些名言,但是如果您连续按下按钮,它将循环浏览所有名言,而无法深思熟虑并通读它们。现在,我尝试了类似下面的操作,但它什么也没做(因为按钮仍然可以被按下并且没有明显的效果):
Bool pressed;
void Function () {
if (pressed) {
//code to call array
}
}
Run Code Online (Sandbox Code Playgroud)
我认为 bool 和 if 循环的简单组合就足够了,但这不起作用。我接近这个概念吗?需要更改什么才能运行此功能?