小编Dan*_*Lip的帖子

如何退出独立模式或编辑器模式

我在 Windows 10 64 位上使用 unity 5.4.1f1 Personal

我将解释我所做的所有步骤以及迄今为止我尝试过的所有事情。

我第一次使用原始代码创建了一个新的 c# 文件: 现在,当我按 Escape 键时,它将返回编辑器,但不会退出游戏!使用[InitializeOnLoad]时,您无法停止编辑器播放按钮并退出游戏。要退出游戏,您只能在独立模式下使用“构建并运行”来完成,然后您可以使用 Application.Quit();

using UnityEditor;
using UnityEngine;
using System.Collections;

[InitializeOnLoad]
public class FullscreenPlayMode : MonoBehaviour {

    //The size of the toolbar above the game view, excluding the OS border.
    private static int tabHeight = 22;

    static FullscreenPlayMode()
    {
        EditorApplication.playmodeStateChanged -= CheckPlayModeState;
        EditorApplication.playmodeStateChanged += CheckPlayModeState;

        EditorApplication.update += Update;

    }

    static void CheckPlayModeState()
    {
        if (EditorApplication.isPlaying)
        {
            FullScreenGameWindow();
        }
        else 
        {
            CloseGameWindow();
        }
    }

    static EditorWindow GetMainGameView(){
        EditorApplication.ExecuteMenuItem("Window/Game");

        System.Type …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

1
推荐指数
1
解决办法
1432
查看次数

为什么在设置执行脚本的顺序时仍然首先执行一个脚本?

我有两个脚本附加到同一个emptygameobject.第一个脚本是:

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class SpawnObjects : MonoBehaviour
{
    public int numberOfObjects;
    public GameObject objectToPlace;
    public Vector3 newObjectsSize = new Vector3(5, 5, 5);
    public float spawnSpeed = 0.1f;

    private int wallsLengthX;
    private int wallsLengthZ;
    private int wallsPosX;
    private int wallsPosZ;
    private int currentObjects;
    private List<GameObject> objects = new List<GameObject>();

    void Start()
    {
        var wi = GetComponent<Walls>();
        wallsLengthX = (int)wi.lengthX;
        wallsLengthZ = (int)wi.lengthZ;
        wallsPosX = (int)wi.wallsStartPosition.x;
        wallsPosZ = (int)wi.wallsStartPosition.z;

        StartCoroutine(Spawn());
    }

    IEnumerator Spawn() …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine unity5

1
推荐指数
1
解决办法
38
查看次数

如何在着色器之间实时切换?

问题是我有两个着色器。如果我在游戏运行时更改着色器,它将不会生效。仅当我使用当前着色器启动游戏时,它才会使用该着色器,但不会使用我切换到的着色器。

我看到了这段代码,但它正在切换材质,我想切换着色器。我的意思是在同一个游戏对象上的着色器之间切换。我不确定这段代码中应该包含哪些材料?

var materials : Material[];
var count = 0;

function OnMouseDown() {
    if (count == materials.Length - 1)
        count = 0;
    else
        count++;

    renderer.material = materials[count];
}
Run Code Online (Sandbox Code Playgroud)

unity-game-engine unityscript

1
推荐指数
1
解决办法
8900
查看次数

如何制作开关按钮?

private void button13_Click(object sender, EventArgs e)
{
   button13.ForeColor = Color.Red;
   debugMode = true;
}
Run Code Online (Sandbox Code Playgroud)

我点击按钮后想要跟随设置:

button13.ForeColor = Color.Red;
debugMode = true;
Run Code Online (Sandbox Code Playgroud)

而下一次我会点击按钮,该按钮会回到Color.BlackdebugModefalse.

如果它在另一个开关上,如果按钮Color.Black并且debugModefalse,我点击按钮,值会改变Color.Red并且debugModetrue.

我已经有一个bool变量用于使用

debugButtonSwitch

c#

0
推荐指数
1
解决办法
1940
查看次数

在单声道for android上c#Resource.id剂量不存在为什么?

我有这个代码:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Speech.Tts;
using System.Collections.Generic;
namespace SayItAndroid{ [Activity (Label = "SayItAndroid", MainLauncher = true)]
    public class Activity1 : Activity, TextToSpeech.IOnInitListener
{
    int count = 1;
    TextToSpeech mTts;
    public void OnInit (int status)
    {
        Console.WriteLine ("Listening to text to speech");
    }
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);// Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);
        Intent checkIntent = new Intent();
        checkIntent.SetAction(TextToSpeech.Engine.ActionCheckTtsData);
        StartActivityForResult(checkIntent, …
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
2004
查看次数

如何添加List <long>另一个数组?

我这样做:

long[] HistogramValues = Form1.GetHistogram(bitmap);
Form1.Histograms.AddRange(HistogramValues);
Run Code Online (Sandbox Code Playgroud)

但是,直方图还包含256个值,如HistogramValues.我希望在索引[0]的直方图中,将有来自HistogramValues的256个值,然后在[1]中还有256个值,然后是[2],依此类推.

直方图是一个列表

c# arrays list

0
推荐指数
1
解决办法
70
查看次数

如何在不重新创建的情况下每次都写入文本文件(新建)?

我有这个按钮点击事件:

private void button6_Click(object sender, EventArgs e)
{
    if (File.Exists(@"d:\Keywords.txt"))
    {
        Dictionary<string,string> test = new Dictionary<string,string>();
        string value_of_each_key;
        string key_of_each_line;
        string line;
        int index;
        sr = new StreamReader(@"d:\Keywords.txt");
        while (null != (line = sr.ReadLine()))
        {
             index = line.IndexOf(",");
             key_of_each_line = line.Substring(0, index);
             value_of_each_key = line.Substring(index + 1);
             test.Add(key_of_each_line, value_of_each_key);
        }
        sr.Close();
     }

     using (var w = new StreamWriter(@"D:\Keywords.txt"))
     {
         crawlLocaly1 = new CrawlLocaly();
         crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
         DialogResult dr = crawlLocaly1.ShowDialog(this);
         if (dr == DialogResult.OK)
         {
             if (LocalyKeyWords.ContainsKey(mainUrl))
             {
                 LocalyKeyWords[mainUrl].Clear();
                 //probably …
Run Code Online (Sandbox Code Playgroud)

c# file-io

0
推荐指数
1
解决办法
278
查看次数

我有这个函数我在最后一行得到一个错误:return l; 会是什么呢?

 public static long[] GetHistogramRGB(Bitmap b)
        {
            long[] myHistogramBlue = new long[256];
            long[] myHistogramGreen = new long[256];
            long[] myHistogramRed = new long[256];
            BitmapData bmData = null;

            try
            {
                //Lock it fixed with 32bpp
                bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                int scanline = bmData.Stride;
                System.IntPtr Scan0 = bmData.Scan0;
                unsafe
                {
                    byte* p = (byte*)(void*)Scan0;
                    int nWidth = b.Width;
                    int nHeight = b.Height;
                    for (int y = 0; y < nHeight; y++)
                    {
                        for (int x = 0; x < …
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
79
查看次数

如何使用一个射线投射并击中多个游戏对象?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OnMouseOverEvent : MonoBehaviour
{
    public GameObject[] objects;

    private Vector3[] originalpos;

    private void Start()
    {
        originalpos = new Vector3[objects.Length];
        for (int i = 0; i < objects.Length; i++)
        {
            originalpos[i] = objects[i].transform.position;
        }
    }

    private void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 100))
        {
            if (hit.transform.tag == "Test")
            {
               // if (transform.position.z != originalpos.z - 3)
                 //   StartCoroutine(moveToX(transform, new Vector3(transform.position.x, transform.position.y, transform.position.z - 3), 0.1f));
            }
            else …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine raycasting gameobject

0
推荐指数
1
解决办法
44
查看次数

如何检查用户是否是第一次玩游戏?

我想第一次显示一个文本,例如“嗨,我叫NAVI”。然后当玩家下次再次开始游戏时,它将显示另一个文字,例如“欢迎回来”。

主菜单

unity-game-engine

0
推荐指数
1
解决办法
33
查看次数

为什么我可以创建这个功能?

private void List<string> removeDuplicates(
    List<string> currentsites, 
    List<string> listintheformlevelsitesvisited)
{
}
Run Code Online (Sandbox Code Playgroud)

我想获得两个列表,但我得到错误.很多错误:

; 期望标识符预期无效令牌)无效令牌> Sysntax错误(

错误10找不到类型或命名空间名称"listintheformlevelsitesvisited"(您是否缺少using指令或程序集引用?)

错误9找不到类型或命名空间名称"removeDuplicates"(您是否缺少using指令或程序集引用?)

我想要的只是一个简单的功能,获得两个列表.怎么了 ?

c#

-1
推荐指数
1
解决办法
97
查看次数

如何循环并将项添加到comboBox,以便从1到8开始?

for (int xx = 0; xx < piCount; xx++)
{
    comboBox1.Items.Add(xx);
}
Run Code Online (Sandbox Code Playgroud)

piCount是int.它的值是8.如果我从0开始我将在comboBox 01234567中看到但我想看到12345678

.net c# winforms

-1
推荐指数
1
解决办法
565
查看次数