小编der*_*ugo的帖子

如何在Unity3D中获得平滑的慢动作

我试图在正在制作的游戏中获得慢动作,但它看起来确实很滞后。我使用 Unity 提供的标准资源中的 FPS 控制器。我将以下脚本附加到它:

function Update () 
{
    if (Input.GetKeyDown ("q"))
    {
        Time.timeScale = 0.5;
    }

    if (Input.GetKeyDown ("e")) 
    {
        Time.timeScale = 2.0;
    }

    if (Input.GetKeyDown ("t")) 
    {
        Time.timeScale = 1.0;
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道这是一个与此类似的问题http://answers.unity3d.com/questions/39279/how-to-get-smooth-slow-motion.html

但对该问题给出的修复不起作用。我尝试向其添加刚体并将插值设置为插值,但它没有执行任何操作。(我从“使用重力”中删除了勾号,因为角色开始飞行)。我是 Unity 和脚本方面的新手,所以请对我宽容点。

谢谢。

unity-game-engine unityscript

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

SQLAlchemy 和 pandas 产生错误(engine.table_names 返回空列表)

我有一个如下所示的代码:

from sqlalchemy import create_engine
import pandas as pd

# load the CSV
df = pd.Series()
df['raw'] = pd.read_csv('./data/Iris.csv',index_col='Id')

# Connect to the mysql, and use database "datasets"
engine = create_engine('mysql://root:root@127.0.0.1')
engine.execute("USE Datasets") # select new db


# Write data
table_name = 'IRIS'
df['raw'].to_sql(table_name, engine, if_exists='append', index=False)
Run Code Online (Sandbox Code Playgroud)

数据已正确插入数据库,之后可以加载,但命令产生错误:

> --------------------------------------------------------------------------- AttributeError                            Traceback (most recent call
> last) <ipython-input-6-cfb9b0f5c930> in <module>()
>       1 table_name = 'IRIS'
>       2 
> ----> 3 df['raw'].to_sql(table_name, engine, if_exists='append', index=False)
> 
> ~/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in
> to_sql(self, …
Run Code Online (Sandbox Code Playgroud)

python sql

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

从另一个脚本访问变量/函数

所以我试图通过触摸一个立方体来改变另一个脚本中的变量.当前设置

  • 1x球员
  • 1x敌人

每个都有自己的脚本Enemy_Stats&Character_Stats
正如你在这个小片段中看到的那样,从另一个脚本访问变量是一个很好的解决方法.

void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.tag == "Enemy")
    {
        collision.gameObject.GetComponent<Enemy_Stats>().Health = 
            collision.gameObject.GetComponent<Enemy_Stats>().Health 
            - gameObject.GetComponent<Character_Stats>().AttackDamage;

        if (collision.gameObject.GetComponent<Enemy_Stats>().Health <= 0)
        {
            Destroy(collision.gameObject);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我刚接触Unity,但是没有办法用它来引用它:
collision.Health

c# unity-game-engine unityscript

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

按 2 次后退按钮退出 Unity3D Android 应用程序

我希望我的应用程序在第一次按下后退按钮时将消息显示为“请再次触摸后退按钮以退出应用程序”,当再次按下时,应用程序应退出。我想我已经添加了适当的代码,但它不起作用。

该脚本作为组件附加到画布元素。该脚本包含我分配给面板(画布的子级)UI 元素的公共变量。

场景层次

观察到: 当我按下后退按钮时,文本出现但只有几分之一秒,然后突然消失,下一次后退按钮按下并没有导致应用程序退出。

Desired 在第一个后退按钮按下它应该显示消息,如果第二个后退按钮按下应用程序应该在 3 秒内退出。

相关资料: Unity 2017.1.0f3

这是代码链接:

https://gist.github.com/bmohanrajbit27/431221fc80e0b247649289fd136f9cfb

public class ChangeSceneScript : MonoBehaviour
{
    private bool iQuit = false;
    public GameObject quitobject;

    void Update()
    {
        if (iQuit == true)
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            quitobject.SetActive(true);
            iQuit = true;
            StartCoroutine(QuitingTimer());

        }
    }

    IEnumerator QuitingTimer()
    {
        yield return new WaitForSeconds(3);
        iQuit = false;
        quitobject.SetActive(false);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

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

如何清除 LineRenderer 路径以重绘线条?

我有一个 LineRenderer 路径来显示高尔夫球的路径。请参见图片中的栗色路径。

在此处输入图片说明

private void createTrail()
{
    lineRenderer.SetColors(tracerColor, tracerColor);
    lineRenderer.SetVertexCount(maxVertexCount);
    for (int idx = 0; idx < (maxVertexCount - 2); idx++)
    {//Add another vertex to show ball's roll
        lineRenderer.SetPosition(idx, new Vector3((float)pts[idx * (int)positionSampling].z, (float)pts[idx * (int)positionSampling].y, (float)pts[idx * (int)positionSampling].x));
    }
    lineRenderer.SetPosition(maxVertexCount - 2, new Vector3((float)pts[goal - 1].z, (float)pts[goal - 1].y, (float)pts[goal - 1].x));
    lineRenderer.SetPosition(maxVertexCount - 1, transform.position);
}
Run Code Online (Sandbox Code Playgroud)

路径是使用 中的点绘制的pts[] array

在重复显示时,我需要清除旧路径以重新绘制相同的路径。如何清除旧路径?

c# unity-game-engine unity3d-2dtools

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

编辑器窗口截图

我想从自定义编辑器窗口捕获屏幕截图,我将其用作我正在开发的游戏的关卡编辑器,但我不确定如何执行此操作。

我想要的是捕获 EditorWindow,而不是游戏视图或场景视图。

你能帮助我吗?谢谢!

编辑:我想在按下 GUILayout.Button 时通过代码截取屏幕截图:)

unity-game-engine unity3d-editor unity-editor

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

如何在统一编辑器中显示以下KeyValuePair(以便可编辑)

简而言之:我有一个 KeyValuePair,我想在检查器中显示并使其可编辑。

我有以下自定义键值对的实现类。

using UnityEngine;
namespace Unit.Properties
{
    public class ClassificationPropertySuperClass : MonoBehaviour, IClassificationUnitProperty
    {
        [SerializeField]
        KeyValuePair<UnitClassifications, float> value;

        public KeyValuePair<UnitClassifications, float> GetComponentValue()
        {
            return value;
        }

        public void SetComponentValue(KeyValuePair<UnitClassifications, float> value)
        {
            this.value = value;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

仅供参考,这是我制作的自定义 KeyValuePair 类

[System.Serializable]
public class KeyValuePair<TKey, TValue>
{
    public KeyValuePair()
    {
    }

    public KeyValuePair(TKey key, TValue value)
    {
        Key = key;
        Value = value;
    }

    public TKey Key { get; set; }
    public TValue Value { get; set; }
} …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine unity-editor

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

Unity:如何通过字符串名称将预制件实例化到某个位置?

我将所有字符串名称保存在一个列表中,以保存玩家拥有的所有预制车辆。

字符串名称是预制名称。

我将如何按名称生成/实例化预制件?

并在特定位置或游戏对象上生成预制件?

谢谢!

unity-game-engine

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

我如何统一启动“play store”(google)?

如何通过 c#code 统一启动“play store”(google)?我无法打开 Play 商店应用程序。请帮助我 这个问题意味着在“Google Play 商店”应用程序中打开链接我的游戏,例如 google play 中的链接:com.ds.aa 请帮助我

unity-container unity-game-engine google-play

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

如何使LookAt对齐transform.up向量而不是transform.forward?

问题是我无法制作一个让敌人旋转的脚本,以便“向上”指向玩家(我的意思是这样它会通过transform.up到达玩家)并且我还没有找到任何有效的方法解决方案还没有,(据我所知)

我正在尝试制作一个小型2D游戏,仅供我的朋友玩。我尝试过的是让敌人看着玩家,然后将“z”旋转设置为与“x”旋转相同,然后重置“x”和“y”旋转(以便“向上”指向)在播放器上)。但敌人却径直上来。

using UnityEngine;
public class Enemy : MonoBehaviour
{
    public Transform Player;  // The Transform of the Player that you can controll
    public float MoveSpeed = 4; // How fast the enemy should go
    void FixedUpdate()
    {
        transform.LookAt(Player);
        transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.x);
        transform.rotation = Quaternion.Euler(0, 0, transform.rotation.z);
        transform.position += transform.up * MoveSpeed * Time.deltaTime;

    }
}
Run Code Online (Sandbox Code Playgroud)

所以我想要发生的是,敌人将移动到玩家身上,但旋转部分不起作用,它只是直接在空中上升,而不是跟随玩家。我可能只是愚蠢,错过了一些简单的事情......

c# artificial-intelligence rotation unity-game-engine

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