我经常用if ( gameobject == null ),但听说游戏里这个很贵。
我检查了if ( gameobject == null )和if ( boolvalue == false ),但没有注意到任何差异。
您能解释一下为什么这项检查费用昂贵吗?先感谢您。
我刚刚打开我的 unity 2d 项目,出现了这 3 个错误,
Library\PackageCache\com.unity.collab-proxy@2.0.3\Editor\PlasticSCM\UI\Images.cs(441,20):错误CS1061:“Texture2D”不包含“ignoreMipmapLimit”的定义并且没有可访问的扩展可以找到接受类型为“Texture2D”的第一个参数的方法“ignoreMipmapLimit”(您是否缺少 using 指令或程序集引用?)
Library\PackageCache\com.unity.collab-proxy@2.0.3\Editor\PlasticSCM\UI\Images.cs(441,48):错误CS1061:“Texture2D”不包含“ignoreMipmapLimit”的定义并且没有可访问的扩展可以找到接受类型为“Texture2D”的第一个参数的方法“ignoreMipmapLimit”(您是否缺少 using 指令或程序集引用?)
Library\PackageCache\com.unity.collab-proxy@2.0.3\Editor\PlasticSCM\UI\Images.cs(451,20):错误CS1061:“Texture2D”不包含“ignoreMipmapLimit”的定义并且没有可访问的扩展可以找到接受类型为“Texture2D”的第一个参数的方法“ignoreMipmapLimit”(您是否缺少 using 指令或程序集引用?)
上次我关闭项目时错误不存在
当我单击错误消息时,它会将我带到一个我从未创建的名为“Images.cs”的脚本
在脚本中,3 个错误位于以下行中的每个“ignoreMipmapLimit”下:
internal static Texture2D GetNewTextureFromTexture(Texture2D texture)
{
Texture2D result = new Texture2D(texture.width, texture.height);
result.ignoreMipmapLimit = texture.ignoreMipmapLimit;
return result;
}
internal static Texture2D GetNewTextureFromBytes(int width, int height, byte[] bytes)
{
Texture2D result = new Texture2D(width, height);
result.LoadImage(bytes);
result.ignoreMipmapLimit = true; // ignore global quality settings
return result;
}
Run Code Online (Sandbox Code Playgroud)
我尝试再次关闭并打开该项目,但错误仍然存在,
我还重新导入了所有资源,但错误仍然存在
脚本A
public class ScriptA: MonoBehaviour{
public List<LootItemsList> _lootItemsListToUse;
[System.Serializable]
public class LootItemsList
{
public GameObject _lootItem;
public Vector3 _lootItemOrigin;
public float _lootColliderActivationTime = 0.5f;
}}
Run Code Online (Sandbox Code Playgroud)
脚本B
public class ScriptB: MonoBehaviour{
public List<LootItemsList> _lootItemsListToUse;
[System.Serializable]
public class LootItemsList
{
public GameObject _lootItem;
public Vector3 _lootItemOrigin;
public float _lootColliderActivationTime = 0.5f;
}
void Start(){
ScriptA scriptA = ObjA.GetComponent<ScriptA>();
_lootItemsListToUse = scriptA._lootItemsListToUse;
}}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:错误 CS0029 无法将类型“System.Collections.Generic.List<ScriptB.LootItemsList>”隐式转换为“System.Collections.Generic.List<ScriptA.LootItemsList>”
我也尝试过这个
_lootItemsListToUse = new List<ScriptA.LootItemsList>((IEnumerable<ScriptA.LootItemsList>)script._lootItemsList);
Run Code Online (Sandbox Code Playgroud)
MS studio 中没有错误,但我在播放时遇到此错误:InvalidCastException:指定的演员无效。(包装类型转换)System.Object.__castclass_with_cache(object,intptr,intptr)
请有人帮我找到复制此列表的正确方法吗?谢谢
我正在为我的游戏制作随机对象生成系统。我遇到的错误是在将生成对象和对象分配给数组时。我这样做是为了让随机数生成器可以从数组中选择一个使用。但是我收到错误消息
NullReferenceException: Object reference not set to an instance of an object
RandomSpawn.Start () (at Assets/RandomSpawn.cs:26)
它即将出现的区域是我的启动函数,在这里我将生成物和对象分配给它们的数组。
public Transform spawn1;
public Transform spawn2;
public Transform spawn3;
public GameObject obj1;
public GameObject obj2;
public GameObject obj3;
private Transform[] spawns;
private GameObject[] objects;
private bool[] spawnUsed;
private bool[] objectUsed;
private int randomRun = 0;
void Start()
{
spawns[0] = spawn1;
spawns[1] = spawn2;
spawns[2] = spawn3;
objects[0] = obj1;
objects[1] = obj2;
objects[2] = obj3;
}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么会收到错误,因为我看不到如何分配错误。这些变量与我为其分配的数组相同。我已经确保它们都已附加到Unity中脚本的正确部分。
我在运行时更改预制对象的颜色有问题。
问题在于,预制件由GameObject组成,并且在其内部是立方体。因此,当您从运行时实例化该对象时,不允许您更改颜色。如何识别创建的对象并更改其颜色或其他属性?
这里是错误的图片:
这是我的项目存储库(分支开发):https : //github.com/emicalvacho/MapaMentalAR
此页面的“消息”是什么?(开始,更新,唤醒等)
是类似于虚拟方法还是事件?
还是“消息”是C#语法之一?
https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
首先,我很抱歉这段文字看起来很奇怪。这是我第一次使用stackoverflow
我开始学习Unity和C#。
今天,我了解了如何统一移动多维数据集,要回顾一下脚本,我认为我失败了。
我将脚本放在Hierarchy的cube1中,单击在C#处构建的解决方案并统一运行。而且没有用。
public class TRAIN : MonoBehaviour
{
// return cube1 to cube. cube1 is name of cube object in unity
GameObject cube = GameObject.Find("cube1");
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//move cube1 to z-axis at speed 1
cube.transform.position += new Vector3(0, 0, 1);
}
}
Run Code Online (Sandbox Code Playgroud)
如何移动多维数据集1?
我使用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)
问题是它不起作用,我将脚本添加到了按钮上,但它不起作用,在我的其他项目中它可以正常工作……但是由于某种原因,现在不行了。