using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Room : MonoBehaviour {
public ClassB classBTestInstance = new ClassB(3);
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
public class ClassB {
public ClassB(int testNum) {
Debug.Log("hello " + testNum);
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
你可以看到它说"Hello 3"两次.我希望了解为什么会出现这种情况?我没看到我把它叫了两次.在image2中,您将看到只有一个房间实例(当我将房间类C#脚本附加到主摄像机时).我没有将此脚本附加到其他任何内容上.
我正在尝试为Samsung Gear VR(与Samsung Galaxy S8)开发一个应用程序,因为它要求我拔出USB电缆才能将手机插入Gear VR设备,所以我无法使用USB调试。
如何将错误和调试消息导出到我可以阅读的文件中,以找出问题所在?
到目前为止,研究表明,Android Unity Player不会保存到其他平台上的日志文件中,而adb是进行USB调试的方法……只有我不能为Gear做到这一点。
c# android unity-game-engine samsung-galaxy-gear virtual-reality
我想在 Unity 中创建一些萤火虫。我想增加光强度,然后等待几秒钟,然后在 Unity 中减少它。当它们生成时,我希望它们增加光强度,等待几秒钟,然后淡出。我怎样才能以干净的方式创建这个“过程”?
private Light pointLight; // The light component of the firefly
private float minLuminosity = 0; // min intensity
private float maxLuminosity = 1; // max intensity
private float luminositySteps = 0.005f; // factor when increasing / decreasing
private float shineDuration = 3; // wait 3 seconds when faded in
private void Start()
{
pointLight = GetComponent<Light>();
pointLight.intensity = Random.Range(minLuminosity, maxLuminosity); // start with a random intensity
StartCoroutine(ChangeIntensity()); // start the process
}
private IEnumerator ChangeIntensity() …Run Code Online (Sandbox Code Playgroud) 我有一个变量,我需要在游戏运行时经常检查.为了简化这一点,检查是:if (score >= achievement1) {do something}.
把这个检查放在Update()每帧调用的函数中似乎有点过分了.
所以相反,我在InvokeRepeating函数中调用Start ();函数:
InvokeRepeating ("checkscoreforachievement", 0f, 2f);
Run Code Online (Sandbox Code Playgroud)
这样聪明还是有更好的方法呢?最终结果应该是在达到一定分数后的几秒钟内,触发成就.
我问的原因是,当我的游戏运行时,我还需要做更多的事情,所以我最终会选择其中的一些进程.想知道这是不是太多的资源消耗.找不到关于这个主题的好文档.
我想在 AR 相机中播放视频。我总共有 10 个视频和一个视频播放器。我正在从服务器下载视频播放器作为资产包,名称为 videoplayer.unit3d 并存储到 SD 卡中。当我扫描 imageTarget 时,我正在使用AssetBundle.LoadFromFile()函数读取视频资产包文件,并且第一次它工作正常。
如果我扫描第二个 imageTarget 它会显示以下错误
“无法加载,因为已经加载了另一个具有相同文件的 AssetBundle”
我试过 a bundle.Unload(true);andCaching.cleanchache()但它不工作抛出同样的错误。也试过bundle.Unload(false);
private void loadObject(string resourcePath, string objectName, TrackableBehaviour trackableBehaviuor, string videoUrl)
{
Debug.Log("Resource path " + resourcePath + " objectName " + objectName);
Debug.Log("Video Url from sd card " + videoUrl);
FileInfo fileInfo = new FileInfo(resourcePath);
if (!fileInfo.Exists)
return;
Debug.Log("File is present");
AssetBundle bundle = AssetBundle.LoadFromFile(resourcePath, 0, 0);//www.assetBundle;
Debug.Log("Bundle data is " + bundle);
if (bundle …Run Code Online (Sandbox Code Playgroud)我如何根据统一检查器中的其他变量值隐藏变量。基本上想象一下:如果我有一个名为“CanSprint”的布尔值和一个名为“SprintSpeed”的浮点数,那么我想这样做,以便当布尔值为真时,浮点数显示,但当布尔值为假时,浮点数隐藏。这只是为了更整洁一点。谢谢!
我正在学习C#,Unity我创建了一个简单的游戏,您可以通过单击"C"键(将变为绿色)更改播放器的颜色(默认情况下为红色).代码可以工作,但问题是,我不知道如何创建一个代码,通过使用相同的键("C")再次将绿色更改为红色.我知道的唯一选择是创建另一个if但使用不同的按钮.这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cubecolor : MonoBehaviour {
// Use this for initialization
void Start () {
gameObject.GetComponent<Renderer> ().material.color = Color.red;
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.C))
gameObject.GetComponent<Renderer> ().material.color = Color.green;
}
}
Run Code Online (Sandbox Code Playgroud) 我有4种颜色。我想让玩家不能连续 2 次使用相同的颜色。当玩家与物体碰撞时,RandomColor()调用 。所以这个函数在游戏过程中被多次调用,有时玩家不会改变他的颜色。
using UnityEngine;
public class ColorManager : MonoBehaviour {
public SpriteRenderer player;
public string playerColor;
public Color[] colors = new Color[4];
private void Awake()
{
RandomColor();
}
public void RandomColor()
{
int index = Random.Range(0, 4);
switch (index)
{
case 0:
player.color = colors[0]; //colors[0] is orange
playerColor = "orange";
break;
case 1:
player.color = colors[1]; //colors[1] is pink
playerColor = "pink";
break;
case 2:
player.color = colors[2]; //colors[2] is blue
playerColor = "blue";
break; …Run Code Online (Sandbox Code Playgroud) 我已经编写了程序,一旦关卡完成,就会弹出一个面板并附加这个按钮。然而这个按钮不起作用。
我已经 - 检查了我的事件系统,检查了光线投射设置,设置了 onclick 事件,还将按钮放在 z 轴上,这样它就不会受到面板的干扰。
我的层次结构
按钮的检查器
画布检查员
c# ×10
android ×1
assetbundle ×1
button ×1
colors ×1
inspector ×1
random ×1
repeat ×1
unityscript ×1