小编Ruz*_*ihm的帖子

在 Unity 中使用 Stockfish Chess AI

早上好。我正在尝试将 Stockfish 实现到 Unity 国际象棋游戏中,有人告诉我最好的方法是使用 Spawn.Process 有谁知道我可以查看并作为参考的现有代码吗?

不同的游戏状态是与人工智能沟通的最佳方式吗?

谢谢!

c# artificial-intelligence unity-game-engine uci

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

当场景发生变化时如何运行一些代码?

不知道我能解释得如何。我有一个加载时不破坏的脚本,因此它可以在两个场景之间移动。然而,在一个场景(最初创建的场景)中,我需要它在每次重新进入该场景时运行启动函数,因为它会绘制出我的一些 UI。这是供参考的代码:

我可以尝试将其放入新脚本中,但我担心由于我每周只在这个项目上工作几个小时,因此会有一些代码我忘记适应此更改,并且它将不再工作。如何重新调用启动函数,或者做类似的事情?

int spriteIndex = 0;
    foreach (Sprite texture in spriteImages) {

        GameObject button = Instantiate (shopButtonPrefab) as GameObject;
        Image buttonImage = button.GetComponent<Image> ();
        Image[] images = button.GetComponentsInChildren<Image>();

        int newIndex = spriteIndex;
        button.GetComponent<Button> ().onClick.AddListener (() => ChangePlayerSkin (newIndex));
        spriteIndex++;
        foreach (Image image in images) {

            if (image != buttonImage) {
                //button.GetComponentInChildren<Image>().sprite = texture;
                //button.transform.SetParent (shopButtonContrainer.transform, false);
                image.sprite = texture;


                break;
            }
            button.transform.SetParent (shopButtonContrainer.transform, false);
        }

    }
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

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

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

我在 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
查看次数

如何检测游戏对象何时进入另一个游戏对象的区域?

我有一个脚本,可以让游戏对象在某个高度移动,例如在 200 处。在地形上,我有另一个游戏对象。我希望当他开始进入另一个游戏对象区域时移动的第一个游戏对象做某事。

喜欢

void OnTriggerEnter(Collider other)
    {
       if (other.gameObject.name == "Base")
      {

      } 
    }
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为变换和“基础”之间没有物理碰撞。变换高度为 200。

我也尝试使用 Raycast hit。在脚本的顶部,我添加了:

Collider col;
Run Code Online (Sandbox Code Playgroud)

然后在更新

    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;
    if (col.Raycast(ray, out hit, 100.0F))
    {
        Debug.Log("Hit !");
    }
Run Code Online (Sandbox Code Playgroud)

但再次转变是在空中。这个想法是在转换开始进入 Base 区域后做一些事情。

c# unity-game-engine

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

Unity“无法加载关联脚本”和“Win32Exception:系统找不到指定的文件”

所以我是 Unity 的新手,我一直在尝试使用附加到角色的脚本来测试场景。但是,它一直显示“无法加载关联的脚本。请修复所有编译错误并分配有效的脚本。” 它还表示文件的名称可能与代码中的名称不同,但事实并非如此,并且还表示代码可能缺少 MonoBehaviour 脚本。它甚至不允许我将脚本附加到角色上,因为它找不到脚本类。

我从互联网上复制并下载了角色移动代码,但它们也不起作用。我也尝试过删除并重新制作 CS 文件,但这也不起作用。即使向角色添加空脚本也不起作用,除非我从“添加组件”中执行此操作

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

public class Movement : MonoBehaviour
{
    SpriteRenderer sprite;
    Rigidbody2D rigid;

    // Start is called before the first frame update
    void Start()
    {
        sprite = GetComponent<SpriteRenderer>();
        rigid = GetComponent<Rigidbody2D>();
    }

    private void FixedUpdate()
    {
        if (Input.GetKey("d"))
            rigid.velocity = new Vector2(2, 0);
        else if (Input.GetKey("a"))
            rigid.velocity = new Vector2(-2, 0);
    }
}
Run Code Online (Sandbox Code Playgroud)

Unity 中也存在这些错误(如果有帮助的话) 在此输入图像描述 在此输入图像描述 在此输入图像描述

c# unity-game-engine

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

如何取消 Unity 中对象的动量?

我在 3D 平台游戏的关卡底部有一个杀戮区,但是当我的滚球重生时,transform.position我会保持动力。仓位被覆盖后如何取消所有动量?

我已经尝试环顾四周,但每个人似乎至少在 5 年前就问过这个问题,当我尝试更改rigidbody.velocityor时rigidbody.angularVelocity,它说“Component.rigidbody”已过时。

提前致谢!

c# unity-game-engine

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

如何在Unity UI设计中查找脚本用法

我被要求维护一个由不同开发人员构建和维护的 Unity 项目。我发现了源 CSharp 文件,我几乎可以肯定这些文件没有被使用。如何从 Unity 项目中安全地删除此类未使用的文件?我担心 UI 设计中的某个地方可能会有一些用法,比如 . 。。

在此输入图像描述

。。。我最终会得到损坏的引用,这些引用更难发现和修复。

编辑:使用“在场景中查找引用”,列出了一大堆引用,但我找不到任何指向相关文件的链接。这是一个例子。。。

在此输入图像描述

c# unity-game-engine visual-studio

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

如何防止相机尺寸发生变化?

我已附上两张屏幕截图来解决我的问题。基本上,在调整游戏视图窗口的大小时,相机的大小也会调整,并且按下播放键时对象会移动。我该如何解决这个问题?

截图供我工作时查看

播放时最大化视图的屏幕截图

c# game-development game-engine unity-game-engine

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

一旦将脚本应用于场景编辑器中的GameObject,我的函数就会运行。我只需要它在运行时影响对象

我有一个简单的脚本,该脚本应抓住GameObject的变换位置和旋转位置,然后在被Raycast击中时将其移回该位置。(当玩家撞到物体时,物体会四处移动)。

对于已经附加了脚本的对象,它的工作正常,但是当我将脚本应用于新的GameObject时,它将在场景编辑器中将变换的值重置为(0,0,0),(0,0,0)。

我敢肯定有一种更聪明的方法可以做到这一点。

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

public class TransformReset : MonoBehaviour
{
    private Transform LocalTransform;
    private Vector3 InitialPos;
    private Quaternion InitialRot;

    private Vector3 CurrentPos;
    private Quaternion CurrentRot;

    void Start()
    {
        InitialPos = transform.position;
        InitialRot = transform.rotation;       
    }

    public void Reset()
    {
        transform.position = InitialPos;
        transform.rotation = InitialRot;
        Debug.Log("resetting position of " + gameObject.name);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的光线投射脚本调用了“ public void Reset()”部分。但是我认为问题在于,它在获得有用的“ InitialPos”值之前先在场景编辑器中运行。

感谢任何帮助和建议。

c# unity-game-engine

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

无法从 C# 中的列表中删除项目

在我的游戏的库存中,如果你放下它,我想删除它。这仅适用于像这样的 foreach 循环:

public List<Item> items = new List<Item>();

public void DeleteItem(Item itemToRemove)
{
    foreach (var item in items)
    {
        items.Remove(itemToRemove);
    }
}
Run Code Online (Sandbox Code Playgroud)

但后来我收到了这个错误:

集合被修改;枚举操作可能无法执行。

当我尝试这个时:

public void DeleteItem(Item itemToRemove)
{
        items.Remove(itemToRemove);
}
Run Code Online (Sandbox Code Playgroud)

没发生什么事。有谁知道如何解决这一问题?

c# list unity-game-engine

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

如何以编程方式更改 Unity 中矩形变换组件的比例?

我想以编程方式修改附加到“损坏弹出”游戏对象的矩形变换组件的“缩放”参数(特别是 x 缩放),如附图所示;但是,我似乎无法修改这个值。我尝试了几种方法(代码如下所示),但似乎没有任何效果。

非常感谢任何帮助或指导!

Unity中的矩形变换组件(图像): Unity中的矩形变换组件(图片)

Vector3 rectScale;
RectTransform rectTransform;
float xScale;

// Start is called before the first frame update
void Start()
{
         
    rectTransform = GetComponent<RectTransform>();
    rectScale = rectTransform.localScale;
    rectScale = new Vector3(3f, transform.localScale.y, transform.localScale.z); //this doesn't work
    xScale = rectTransform.localScale.x;
    xScale = *any number*; // this doesn't work
   
}

void Update()
{
    rectScale = new Vector3(3f, transform.localScale.y, transform.localScale.z); //this doesn't work
    xScale = *any number* //this doesn't work
}
Run Code Online (Sandbox Code Playgroud)

c# transform rect scale unity-game-engine

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

2019.1.9如何统一黑白相机?

我想制作一个统一黑白的滤镜相机 2019.1.9 我该如何制作?那可以每次都改成RGB和黑白

c# unity-game-engine

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

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