我有2个带有两个不同项目的Visual Studio Code实例。
有没有一种方法可以使VS Code实例的主题根据项目而彼此不同?
我正在实例化许多按钮,当点击时需要调用一个函数(通过监听器).但我也经常摧毁它们.这些听众是否也被销毁或者我是否需要删除它们?
例:
public void makeButton()
{
GameObject spawnedButton = Instantiate(prefabButton, prefabButton.transform.position, prefabButton.transform.rotation) as GameObject;
spawnedButton.GetComponent<Button>().onClick.AddListener(()=>
{
listedButtonClicked(someOtherObjectThatWillNotBeDeleted, spawnedButton);
});
}
public void listedButtonClicked(GameObject target, GameObject button)
{
Debug.Log(target);
Debug.Log(button);
}
Run Code Online (Sandbox Code Playgroud)
......所以什么时候spawnedButton被摧毁,这个听众会留下来吗?我正在实例化并删除大量按钮,因此它可能与我相关.
我正在尝试为一些大学作品制作一个排名表。想到的更好的方法是为每个位置创建一个包含字符串和整数的列表。我在文档中搜索:https://unity3d.com/es/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries ?gq=sort,在那里我找到了解决我的问题的完美示例,所以我开始工作。现在,我已经创建了界面:
public class Name_Puntuation: IComparable
public string namePlayer;
public int puntuation;
public Name_Puntuation( string newNomPlayer, int newPuntuation){
nomPlayer = newNomPlayer;
puntuation= newPuntuation;
}
public int CompareTo(Name_Puntuation other){
if (other == null) {
return 1;
}
return Puntuation - other.Puntuation;
}
Run Code Online (Sandbox Code Playgroud)
我还在我的 GameController 中添加了我想要对列表执行的操作。该类控制游戏的画布。我们将所有信息打印到文本字段,所以我想处理排名:
public class GameController : MonoBehaviour {
public List <Name_Puntuation> ranking;
void Start () {
playerName= GetComponent<MenuController> ().inp; //name the player choosed
ranking = new List<Name_Puntuation> ();
}
void Update () { }
public void Ranking(){ …Run Code Online (Sandbox Code Playgroud) 我有两个对象:
对象 A(SteamVR 相机):
对象 B(地球模型):
我确保碰撞器范围正确,但不知何故,OnCollisionEnter 方法没有被触发。
我用于 OnCollisionEnter 的代码如下所示:
private void OnCollisionEnter(Collision collision)
{
Debug.Log("Collision entered");
}
Run Code Online (Sandbox Code Playgroud)
有人可以给我一些见解/建议吗?
谢谢转发。
我目前有一个脚本应该实例化粒子系统并在一段时间后销毁它,但在实例化对象后,此错误代码显示:
MissingReferenceException:'ParticleSystem'类型的对象已被销毁,但您仍在尝试访问它.您的脚本应该检查它是否为null或者您不应该销毁该对象.
该脚本目前是这样的:
public class MuzzleFlash : MonoBehaviour {
public Transform gun;
public ParticleSystem smoke;
public ParticleSystem flare;
public ParticleSystem bullet;
private float smokeTime = 0.2f;
private void Update () {
if (Input.GetButtonDown("Fire1"))
{
smokeFun();
flare.Play();
bullet.Play();
}
}
void smokeFun()
{
Instantiate(smoke, gun);
Destroy(smoke, smokeTime);
}
}
Run Code Online (Sandbox Code Playgroud)
}
我如何实例化这个粒子系统并正确销毁它?
我有一个在后台运行的计时器,在我要显示排行榜的级别结束时.我想拿这个计时器并将其转换为00:00格式00(分钟):00(秒)(即01:40).怎么可能?我只需要在等级结束时进行计算和转换.
这就是我现在拥有的.我正常启动计时器
void Update()
{
if(timerIsRunning)
{
mainGameTimer += Time.deltaTime;
}
}
Run Code Online (Sandbox Code Playgroud)
现在要以00:00格式添加计时器,我需要将其作为float传递,但在排行榜中将其作为字符串读取
public void ShowResult()
{
int min = Mathf.FloorToInt(mainGameTimer / 60);
int sec = Mathf.FloorToInt(mainGameTimer % 60);
users.Add(new User(userName, score , timeScore));
users.Sort(delegate (User us1, User us2)
{ return us2.GetScore().CompareTo(us1.GetScore()); });
int max = users.Count <= 10 ? users.Count : 10;
for (int i = 0; i < max; i++)
{
//leaderListName[i].text = users[i].GetName() + "- " + users[i].GetScore() + "-" + Mathf.RoundToInt(users[i].GetTimeScore()) + "Sec";
leaderListName[i].text = users[i].GetName(); …Run Code Online (Sandbox Code Playgroud) 我有一个简单的代码,当玩家输入一个触发器时显示一个精灵:
ps:精灵不在GUI上
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
ItemCard.SetActive(true);
}
else
{
ItemCard.SetActive(false);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我SetActive(false)没有工作,精灵仍在展示.我在伪造什么?
我刚开始学习团结和游戏开发以及编码,今天才开始。我只是想让我的玩家加入WALK,但我遇到了我的第一个问题,我一直收到此错误消息,但是没有我的代码有任何错误的迹象(在我看来,这对您可能很明显),但我确实需要帮助
我尝试过许多不同的方法来重做它。我正在关注角色移动教程,但这是从2018年开始的另一版本的Visual Studio代码。
public class PlayerMovement : MonoBehaviour {};
public CharacterController2D controller;
Run Code Online (Sandbox Code Playgroud)
这是链接https://www.youtube.com/watch?v=dwcT-Dch0bA&t=341s我是一个非常新的人,所以如果您可以发送链接到一个有用的2D游戏设计教程,那将是非常棒的。