我遇到的问题是我捡起一个掉落的物品,给枪添加弹药。
使用所有方法和变量构建了一个 Gun 类。构建了一个从 Gun 类派生的 Rifle 类 The Rifle 完美无缺
我现在正在添加一个“拾取”系统,其中 x 数量的敌人会掉落拾取物。
这是要拾取的项目上的脚本
public class AddARAmmo : MonoBehaviour
{
private Rifle rifle;
private void Awake()
{
rifle = FindObjectOfType<Rifle>();
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == string.Format("Player"))
{
rifle.AddAmmo(30);
Destroy(gameObject);
}
}
}
Run Code Online (Sandbox Code Playgroud)
步枪和枪的脚本有点长,但这里是枪基类中的相关内容是公共抽象类......
public int bulletsInStock;
public void AddAmmo(int ammoToAdd)
{
bulletsInStock += ammoToAdd;
UpdateAmmo();// updates on screen Ammo
}
......
Run Code Online (Sandbox Code Playgroud)
然后在步枪班
public override void Modifiers() // This is where the guns starts are stored …Run Code Online (Sandbox Code Playgroud) 该文档说明了iOS/Windows版本中使用的标识符,而不是Android版本.SystemInfo.deviceUniqueIdentifier在Android 上使用什么标识符?
我刚刚在Android上尝试了我的应用程序,它突然无法正常工作(在Windows上运行正常).有没有办法看到统一控制台的错误和Debug.Log消息 - 当我在Android上运行设备?(我使用开发模式和脚本调试).
我将adb连接到设备,也可以使用logcat和filter来"统一",但它仍然显示一个疯狂的日志.
我想看到的只是一个干净的日志,显示错误和我的Debug.Log消息,我通常可以在Unity上的Unity控制台上看到简单明了.
我在移动2D统一游戏中有多个场景,我想在启动画面中加载我的所有场景,以便场景传递顺畅.我怎样才能做到这一点 ?
如果我这样做,我是否需要更改"Application.LoadScene()"方法,我可以使用哪种方法?
我在构建游戏时遇到此错误。
无法加载文件或程序集“UnityEngine.Purchasing, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”或其依赖项之一。
控制台截图:
我是 Unity 的新手,正在尝试运行现有的源代码。
我正在尝试 Unity 的新预制工作流程。我想以编程方式在我已经创建的预制件上创建预制件变体。我使用的是Unity 2018.3.0b7。如何才能做到这一点?
我刚刚开始学习C#和Unity,有一件事我不习惯:
我应该何时何地使用[SerializeField]?
尽管使用[SerializeField]并且在我的Unity界面中有更多的文本框,但是将变量保留为硬编码是不是很糟糕?
提前感谢您的关注和耐心.
我正在尝试使用这行代码更改 UI 按钮上的颜色。
prev.GetComponent<Button>().colors.normalColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误
Assets/_Scripts/OptionSwitch.cs(28,53):错误CS1612:无法修改“UnityEngine.UI.Selectable.colors”的值类型返回值。考虑将值存储在临时变量中
我尝试在调用按钮和颜色之前将它们存储为变量,但它不会更改错误代码。
编辑:
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Sprites;
public class OptionSwitch : MonoBehaviour {
ColorBlock colorBlock = new ColorBlock();
colorBlock.normalColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);
[MenuItem ("GameObject/UI/Switch")]
static void Switch(){
if (GameObject.FindObjectOfType (typeof(Canvas)) != null) {
Canvas canvas = (Canvas)GameObject.FindObjectOfType (typeof(Canvas));
// Define Previous Button
GameObject prev = new GameObject ("Previous", typeof(Button));
prev.layer = 5;
prev.AddComponent<Image> ();
prev.transform.parent = canvas.transform;
prev.GetComponent<Image> ().sprite …Run Code Online (Sandbox Code Playgroud) I have a MovieController class that manages videos in my project. I'm using the new video player component introduced in Unity 5.6.
I would like to call a method when a movie has finished playing. So far, this method is only a Debug.Log, as you can see:
using UnityEngine;
using UnityEngine.Video;
public class MovieController : MonoBehaviour
{
private VideoPlayer m_VideoPlayer;
void Awake ()
{
m_VideoPlayer = GetComponent<VideoPlayer>();
m_VideoPlayer.loopPointReached += OnMovieFinished; // loopPointReached is the event for the end of …Run Code Online (Sandbox Code Playgroud) 我的场景中有一个淡入淡出面板gameobject,它必须位于所有其他游戏对象之上。但是,当我单击编辑器窗口中的某个对象时,由于该对象gameobject位于所有对象之上,因此是在层次结构中自动选择的对象。
有没有办法将 保持gameobject在画布顶部,就像现在一样,但当我单击场景时使其完全不可选择?