小编Any*_*nya的帖子

'for x ...'中'x'的技术术语是什么?

如果我有代码......

list = ['Clemont', 'Albert', 'Shiro']
for x in range(len(list)):
    print(x)
Run Code Online (Sandbox Code Playgroud)

...... x这里的技术术语是什么?我假设它是"迭代对象",但也许这是一种误解; 如果它不是一个误解,什么是迭代对象?

python python-3.x

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

对'open'函数如何在Python中工作感到困惑

说我有代码:

 file = open('items.txt', 'r')
 print(file.read())
Run Code Online (Sandbox Code Playgroud)

这很好,只打印整个文本文件,但是:

 file = open('items.txt', 'r')
 for line in file:
     print(line)
 print(file.read())
Run Code Online (Sandbox Code Playgroud)

所以它将运行for循环就好了并打印线,但最后一行不会做任何事情.使用第二个代码,它应该打印整个文件两次,但它只打印一次.有人能解释为什么吗?

python python-3.x

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

在非活动/停用的游戏对象上启动协程

我有以下代码:

void Start()
{
    gameObject.SetActive(false);
    StartCoroutine(Load());
}

IEnumerator Load()
{
    yield return new WaitForSeconds(waitTime);
    gameObject.SetActive(true);
}
Run Code Online (Sandbox Code Playgroud)

这给了我一个错误:

协程无法启动,因为游戏对象“NameOfObj”处于非活动状态!

这是有道理的,因为游戏对象已在运行脚本之前设置为停用。即便如此,那我该怎么办呢?我gameObject.SetActive(false)之前尝试过转移到协程WaitForSeconds()。这样做会完全阻止游戏对象加载。

根据我的理解,当执行该行时gameObject.SetActive(false),脚本将停止运行,直到重新激活游戏对象。但是,如果是这种情况,那么重新激活游戏对象是不是不可能(因为脚本被禁用)?

无论如何,如何将游戏对象延迟到游戏开始后 2-3(或任意任意时间长度)加载?

c# unity-game-engine

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

找到变量变化后的时间

您如何找到自某个变量发生变化以来的时间?以一个布尔变量为例,您如何找到自上次更改以来的时间?我想使用布尔变量作为触发器(当它为真时激活触发器),但仅在经过一段精确的,恒定的时间(例如0.5秒)后才更改为真(它只能从false更改为真正).

这是我的代码:

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

public class hitRegistration : MonoBehaviour
{

    AudioSource hitSound;
    private bool hitState = false;
    // Use this for initialization
    void Start()
    {
        hitSound = gameObject.GetComponent<AudioSource>();
    }
    void OnMouseOver()
    {
        Debug.Log("Mouse is over game object.");
        if (Input.GetKey(KeyCode.X) && hitState == false)
        {
            hitSound.Play();
            hitState = true;
        }
    }
    private void OnMouseExit()
    {
        Debug.Log("Mouse is no longer over game object.");
        if (hitState == true)
        {
            // sound clip gets cut if the cursor leaves before …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

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

标签 统计

c# ×2

python ×2

python-3.x ×2

unity-game-engine ×2